mirror of
https://github.com/neocities/neocities.git
synced 2025-04-24 17:22:35 +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}
|
||||
end
|
||||
|
||||
if SimpleCache.expired?(:index)
|
||||
@sites_count = Site.count.roundup(100)
|
||||
@total_hits_count = DB['SELECT SUM(hits) AS hits FROM SITES'].first[:hits] || 0
|
||||
@total_views_count = DB['SELECT SUM(views) AS views FROM SITES'].first[:views] || 0
|
||||
@changed_count = DB['SELECT SUM(changed_count) AS changed_count FROM SITES'].first[:changed_count] || 0
|
||||
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)
|
||||
@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 = ''
|
||||
|
||||
begin
|
||||
|
@ -45,15 +71,21 @@ get '/?' do
|
|||
@blog_feed_html = 'The latest news on Neocities can be found on our blog.'
|
||||
end
|
||||
|
||||
@create_disabled = false
|
||||
|
||||
@index_rendered = SimpleCache.store :index, erb(:index, layout: :index_layout), (ENV['RACK_ENV'] == 'test' ? -1 : 1.hour)
|
||||
@blog_feed_html = SimpleCache.store :blog_feed_html, @blog_feed_html, 8.hours
|
||||
else
|
||||
@index_rendered = SimpleCache.get(:index)
|
||||
@blog_feed_html = SimpleCache.get :blog_feed_html
|
||||
end
|
||||
|
||||
@index_rendered.gsub! 'CSRF_TOKEN_HERE', csrf_token
|
||||
@index_rendered
|
||||
if SimpleCache.expired?(:featured_sites)
|
||||
@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
|
||||
|
||||
get '/welcome' do
|
||||
|
|
|
@ -32,6 +32,8 @@
|
|||
</ul>
|
||||
</nav>
|
||||
|
||||
<%== flash_display centered: true %>
|
||||
|
||||
<div class="int-Logo hp-Logo">
|
||||
<a href="/" title="back to home">
|
||||
<span class="hidden">Neocities.org</span>
|
||||
|
@ -89,7 +91,7 @@
|
|||
</div>
|
||||
<% else %>
|
||||
<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">
|
||||
<fieldset class="content">
|
||||
<h2 class="gamma">Sign up for free</h2>
|
||||
|
@ -162,10 +164,10 @@
|
|||
<div class="nav prev"></div>
|
||||
-->
|
||||
<ul class="website-Gallery hp-Gallery">
|
||||
<% Site.order(:score.desc).limit(12).all.shuffle.each do |site| %>
|
||||
<% @featured_sites.each do |site| %>
|
||||
<li>
|
||||
<a href="<%= site.uri %>" title="<%= site.title %>" target="_blank">
|
||||
<img src="<%= site.screenshot_url 'index.html', '540x405' %>" class="neo-SS" alt="<%= site.title %>" />
|
||||
<a href="<%= site[:uri] %>" title="<%= site[:title] %>" target="_blank">
|
||||
<img src="<%= site[:screenshot_url] %>" class="neo-SS" alt="<%= site[:title] %>" />
|
||||
</a>
|
||||
</li>
|
||||
<% end %>
|
||||
|
@ -342,4 +344,4 @@
|
|||
</footer>
|
||||
</div>
|
||||
<%== erb :'_index_signup_script', layout: false %>
|
||||
</body>
|
||||
</body>
|
Loading…
Add table
Reference in a new issue