mirror of
https://github.com/neocities/neocities.git
synced 2025-04-25 09:42:36 +02:00
index: cache featured sites, fixes signup issues
This commit is contained in:
parent
53c258d58f
commit
ea45da0dbd
2 changed files with 50 additions and 16 deletions
54
app/index.rb
54
app/index.rb
|
@ -28,11 +28,37 @@ get '/?' do
|
||||||
halt erb :'home', locals: {site: current_site}
|
halt erb :'home', locals: {site: current_site}
|
||||||
end
|
end
|
||||||
|
|
||||||
if SimpleCache.expired?(:index)
|
if SimpleCache.expired?(:sites_count)
|
||||||
@sites_count = Site.count.roundup(100)
|
@sites_count = SimpleCache.store :sites_count, Site.count.roundup(100), 4.hours
|
||||||
@total_hits_count = DB['SELECT SUM(hits) AS hits FROM SITES'].first[:hits] || 0
|
else
|
||||||
@total_views_count = DB['SELECT SUM(views) AS views FROM SITES'].first[:views] || 0
|
@sites_count = SimpleCache.get :sites_count
|
||||||
@changed_count = DB['SELECT SUM(changed_count) AS changed_count FROM SITES'].first[:changed_count] || 0
|
end
|
||||||
|
|
||||||
|
if SimpleCache.expired?(:total_hits_count)
|
||||||
|
@total_hits_count = SimpleCache.store :total_hits_count, DB['SELECT SUM(hits) AS hits FROM SITES'].first[:hits], 4.hours
|
||||||
|
else
|
||||||
|
@total_hits_count = SimpleCache.get :total_hits_count
|
||||||
|
end
|
||||||
|
|
||||||
|
@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
|
||||||
|
@ -45,15 +71,21 @@ 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
|
||||||
|
|
||||||
@create_disabled = false
|
@blog_feed_html = SimpleCache.store :blog_feed_html, @blog_feed_html, 8.hours
|
||||||
|
|
||||||
@index_rendered = SimpleCache.store :index, erb(:index, layout: :index_layout), (ENV['RACK_ENV'] == 'test' ? -1 : 1.hour)
|
|
||||||
else
|
else
|
||||||
@index_rendered = SimpleCache.get(:index)
|
@blog_feed_html = SimpleCache.get :blog_feed_html
|
||||||
end
|
end
|
||||||
|
|
||||||
@index_rendered.gsub! 'CSRF_TOKEN_HERE', csrf_token
|
if SimpleCache.expired?(:featured_sites)
|
||||||
@index_rendered
|
@featured_sites = Site.order(:score.desc).limit(12).all.shuffle.collect {|s| {screenshot_url: s.screenshot_url('index.html', '540x405'), uri: s.uri, title: s.title}}
|
||||||
|
SimpleCache.store :featured_sites, @featured_sites, 1.hour
|
||||||
|
else
|
||||||
|
@featured_sites = SimpleCache.get :featured_sites
|
||||||
|
end
|
||||||
|
|
||||||
|
@create_disabled = false
|
||||||
|
|
||||||
|
erb :index, layout: :index_layout
|
||||||
end
|
end
|
||||||
|
|
||||||
get '/welcome' do
|
get '/welcome' do
|
||||||
|
|
|
@ -32,6 +32,8 @@
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
|
<%== flash_display centered: true %>
|
||||||
|
|
||||||
<div class="int-Logo hp-Logo">
|
<div class="int-Logo hp-Logo">
|
||||||
<a href="/" title="back to home">
|
<a href="/" title="back to home">
|
||||||
<span class="hidden">Neocities.org</span>
|
<span class="hidden">Neocities.org</span>
|
||||||
|
@ -89,7 +91,7 @@
|
||||||
</div>
|
</div>
|
||||||
<% else %>
|
<% else %>
|
||||||
<form id="createSiteForm" class="signup-Form" onsubmit="return false">
|
<form id="createSiteForm" class="signup-Form" onsubmit="return false">
|
||||||
<input type="hidden" name="csrf_token" value="CSRF_TOKEN_HERE">
|
<input type="hidden" name="csrf_token" value="<%= csrf_token %>">
|
||||||
<input type="hidden" name="is_education" value="false">
|
<input type="hidden" name="is_education" value="false">
|
||||||
<fieldset class="content">
|
<fieldset class="content">
|
||||||
<h2 class="gamma">Sign up for free</h2>
|
<h2 class="gamma">Sign up for free</h2>
|
||||||
|
@ -162,10 +164,10 @@
|
||||||
<div class="nav prev"></div>
|
<div class="nav prev"></div>
|
||||||
-->
|
-->
|
||||||
<ul class="website-Gallery hp-Gallery">
|
<ul class="website-Gallery hp-Gallery">
|
||||||
<% Site.order(:score.desc).limit(12).all.shuffle.each do |site| %>
|
<% @featured_sites.each do |site| %>
|
||||||
<li>
|
<li>
|
||||||
<a href="<%= site.uri %>" title="<%= site.title %>" target="_blank">
|
<a href="<%= site[:uri] %>" title="<%= site[:title] %>" target="_blank">
|
||||||
<img src="<%= site.screenshot_url 'index.html', '540x405' %>" class="neo-SS" alt="<%= site.title %>" />
|
<img src="<%= site[:screenshot_url] %>" class="neo-SS" alt="<%= site[:title] %>" />
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
Loading…
Add table
Reference in a new issue