diff --git a/app.rb b/app.rb index d5f37947..808bcbb5 100644 --- a/app.rb +++ b/app.rb @@ -71,6 +71,12 @@ get '/stats_mockup' do end get '/?' do + if SimpleCache.expired?(:sites_count) + @sites_count = SimpleCache.store :sites_count, Site.count.roundup(100), 600 # 10 Minutes + else + @sites_count = SimpleCache.get :sites_count + end + erb :index, layout: false end diff --git a/environment.rb b/environment.rb index eb4289a0..22654ad9 100644 --- a/environment.rb +++ b/environment.rb @@ -96,3 +96,13 @@ class Sinatra::Base render_original engine, data, options, locals, &block end end + +class Numeric + def roundup(nearest=10) + self % nearest == 0 ? self : self + nearest - (self % nearest) + end + + def rounddown(nearest=10) + self % nearest == 0 ? self : self - (self % nearest) + end +end \ No newline at end of file diff --git a/models/simple_cache.rb b/models/simple_cache.rb new file mode 100644 index 00000000..3c10ad57 --- /dev/null +++ b/models/simple_cache.rb @@ -0,0 +1,25 @@ +require 'thread' +require 'time' + +module SimpleCache + @cache = {} + @semaphore = Mutex.new + + class << self + def store(name, value, timeout=30) + @semaphore.synchronize { + @cache[name] = {value: value, expires_at: Time.now+timeout} + } + value + end + + def get(name) + @cache[name][:value] + end + + def expired?(name) + return false if @cache[name] && @cache[name][:expires_at] > Time.now + true + end + end +end \ No newline at end of file diff --git a/views/_footer.erb b/views/_footer.erb index 0b67007f..a40f674b 100644 --- a/views/_footer.erb +++ b/views/_footer.erb @@ -3,15 +3,17 @@

- Neocities.org is a completely open source startup. Follow us on twitter. + Neocities.org is a completely open source project. Follow us on twitter.

diff --git a/views/_header.erb b/views/_header.erb index a755b9a9..b7c43963 100644 --- a/views/_header.erb +++ b/views/_header.erb @@ -7,9 +7,6 @@ diff --git a/views/plan/index.erb b/views/plan/index.erb index 6c1c88af..05ecbadf 100644 --- a/views/plan/index.erb +++ b/views/plan/index.erb @@ -6,7 +6,7 @@
-

Support Neocities

+

Support Neocities

@@ -28,7 +28,7 @@ Manage plan <% else %> <% if current_site %> -

You currently have the Free Plan (<%= current_site.maximum_space_in_megabytes %>MB). You should upgrade to the Neocities Supporter Plan!

+

You currently have the Free Plan (<%= current_site.maximum_space_in_megabytes %>MB). Need more space? Become a Neocities Supporter!

Why upgrade?

<% else %> diff --git a/views/settings.slim b/views/settings.slim index 74b8c100..dbb1e889 100644 --- a/views/settings.slim +++ b/views/settings.slim @@ -17,8 +17,8 @@ p.tiny You currently have the Supporter Plan (#{current_site.maximum_space_in_megabytes}MB). Thank you! We love you. a.btn-Action href="/plan" Manage Plan - else - p.tiny You currently have the Free Plan (#{current_site.maximum_space_in_megabytes}MB).
Need more space, or want to help support Neocities? Upgrade! - a.btn-Action href="/plan" Upgrade Plan + p.tiny You currently have the Free Plan (#{current_site.maximum_space_in_megabytes}MB).
Want to get more space and help Neocities? Become a supporter! + a.btn-Action href="/plan" Supporter Info .row .col.col-33