mirror of
https://github.com/neocities/neocities.git
synced 2025-04-25 09:42:36 +02:00
cache the entire rendering of the front page
This commit is contained in:
parent
6c0ecf752c
commit
88f419ce67
1 changed files with 11 additions and 36 deletions
47
app/index.rb
47
app/index.rb
|
@ -32,37 +32,12 @@ get '/?' do
|
||||||
halt erb :'home', locals: {site: current_site}
|
halt erb :'home', locals: {site: current_site}
|
||||||
end
|
end
|
||||||
|
|
||||||
if SimpleCache.expired?(:sites_count)
|
|
||||||
@sites_count = SimpleCache.store :sites_count, Site.count.roundup(100), 4.hours
|
|
||||||
else
|
|
||||||
@sites_count = SimpleCache.get :sites_count
|
|
||||||
end
|
|
||||||
|
|
||||||
if SimpleCache.expired?(:total_hits_count)
|
if SimpleCache.expired?(:index)
|
||||||
@total_hits_count = SimpleCache.store :total_hits_count, DB['SELECT SUM(hits) AS hits FROM SITES'].first[:hits], 4.hours
|
@sites_count = Site.count.roundup(100)
|
||||||
else
|
@total_hits_count = DB['SELECT SUM(hits) AS hits FROM SITES'].first[:hits] || 0
|
||||||
@total_hits_count = SimpleCache.get :total_hits_count
|
@total_views_count = DB['SELECT SUM(views) AS views FROM SITES'].first[:views] || 0
|
||||||
end
|
@changed_count = DB['SELECT SUM(changed_count) AS changed_count FROM SITES'].first[:changed_count] || 0
|
||||||
|
|
||||||
@total_hits_count ||= 0
|
|
||||||
|
|
||||||
if SimpleCache.expired?(:total_views_count)
|
|
||||||
@total_views_count = SimpleCache.store :total_views_count, DB['SELECT SUM(views) AS views FROM SITES'].first[:views], 4.hours
|
|
||||||
else
|
|
||||||
@total_views_count = SimpleCache.get :total_views_count
|
|
||||||
end
|
|
||||||
|
|
||||||
@total_views_count ||= 0
|
|
||||||
|
|
||||||
if SimpleCache.expired?(:changed_count)
|
|
||||||
@changed_count = SimpleCache.store :changed_count, DB['SELECT SUM(changed_count) AS changed_count FROM SITES'].first[:changed_count], 4.hours
|
|
||||||
else
|
|
||||||
@changed_count = SimpleCache.get :changed_count
|
|
||||||
end
|
|
||||||
|
|
||||||
@changed_count ||= 0
|
|
||||||
|
|
||||||
if SimpleCache.expired?(:blog_feed_html)
|
|
||||||
@blog_feed_html = ''
|
@blog_feed_html = ''
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
@ -75,14 +50,14 @@ get '/?' do
|
||||||
@blog_feed_html = 'The latest news on Neocities can be found on our blog.'
|
@blog_feed_html = 'The latest news on Neocities can be found on our blog.'
|
||||||
end
|
end
|
||||||
|
|
||||||
@blog_feed_html = SimpleCache.store :blog_feed_html, @blog_feed_html, 8.hours
|
|
||||||
else
|
|
||||||
@blog_feed_html = SimpleCache.get :blog_feed_html
|
|
||||||
end
|
|
||||||
|
|
||||||
@create_disabled = false
|
@create_disabled = false
|
||||||
|
|
||||||
erb :index, layout: :index_layout
|
@index_rendered = SimpleCache.store :index, erb(:index, layout: :index_layout), 1.hour
|
||||||
|
|
||||||
|
return @index_rendered
|
||||||
|
else
|
||||||
|
return SimpleCache.get(:index)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
get '/welcome' do
|
get '/welcome' do
|
||||||
|
|
Loading…
Add table
Reference in a new issue