From 3b0dd09b97bee3239229f9d1c8c56711cdd72035 Mon Sep 17 00:00:00 2001 From: Kyle Drake Date: Wed, 23 Apr 2014 15:07:00 -0700 Subject: [PATCH 1/5] more copy fixes --- app.rb | 6 ++++++ environment.rb | 10 ++++++++++ models/simple_cache.rb | 25 +++++++++++++++++++++++++ views/_footer.erb | 11 ++++++----- views/_header.erb | 3 --- views/index.erb | 7 +++---- 6 files changed, 50 insertions(+), 12 deletions(-) create mode 100644 models/simple_cache.rb 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..430cc49a 100644 --- a/views/_footer.erb +++ b/views/_footer.erb @@ -3,15 +3,16 @@

- 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 @@ From 86f38fb137f7b305d2dc0149c614018195c22d8f Mon Sep 17 00:00:00 2001 From: Kyle Drake Date: Wed, 23 Apr 2014 15:07:40 -0700 Subject: [PATCH 2/5] font size fix --- views/index.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/index.erb b/views/index.erb index 66b54fca..68b4983a 100644 --- a/views/index.erb +++ b/views/index.erb @@ -134,7 +134,7 @@
  • -

    Making the web fun again

    +

    Making the web fun again

    We're community of over <%= @sites_count.to_s.reverse.gsub(/...(?=.)/,'\&,').reverse %> websites that are bringing back creative expression on the web. Anyone can make a site, only your imagination is required. Join us!

  • From 478b102f87defb468de3677215c8433a4d28465d Mon Sep 17 00:00:00 2001 From: Kyle Drake Date: Wed, 23 Apr 2014 15:14:24 -0700 Subject: [PATCH 3/5] copy copy copy copy copy copy blah blah --- views/plan/index.erb | 2 +- views/settings.slim | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/views/plan/index.erb b/views/plan/index.erb index 6c1c88af..1a30168d 100644 --- a/views/plan/index.erb +++ b/views/plan/index.erb @@ -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 From ed3d64fc426a9aa1a310e5cfc62d2bde4b41676b Mon Sep 17 00:00:00 2001 From: Kyle Drake Date: Wed, 23 Apr 2014 15:17:27 -0700 Subject: [PATCH 4/5] coooppppyyy --- views/_footer.erb | 3 ++- views/plan/index.erb | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/views/_footer.erb b/views/_footer.erb index 430cc49a..a40f674b 100644 --- a/views/_footer.erb +++ b/views/_footer.erb @@ -8,7 +8,8 @@