Skip to content

Commit

Permalink
use the thread object cache on the main pages
Browse files Browse the repository at this point in the history
  • Loading branch information
reednj committed Aug 24, 2016
1 parent adea6dc commit 2a9e222
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,13 @@ def site_list
get '/?:cur_site?/' do |cur_site|
cur_site ||= 'so'

count_data = {
:comments => Tag.with_name("#{cur_site}-comment-count").latest_value,
:answers => Tag.with_name("#{cur_site}-answer-count").latest_value,
:questions => Tag.with_name("#{cur_site}-question-count").latest_value
}
count_data = cache_object(:for => 60.0) do
{
:comments => Tag.with_name("#{cur_site}-comment-count").latest_value,
:answers => Tag.with_name("#{cur_site}-answer-count").latest_value,
:questions => Tag.with_name("#{cur_site}-question-count").latest_value
}
end

erb :home, :layout => :_layout, :locals => {
:count_data => count_data,
Expand All @@ -75,7 +77,10 @@ def site_list

so_tag_display = so_tag
tag_name = "#{cur_site}-tag-#{so_tag}"
count_data = Tag.with_name(tag_name).latest_value
count_data = cache_object(:for => 60.0 * 15) do
Tag.with_name(tag_name).latest_value
end

halt 404, 'tag not found' if count_data.nil?

erb :tag, :layout => :_layout, :locals => {
Expand Down

0 comments on commit 2a9e222

Please sign in to comment.