Skip to content

Commit

Permalink
Merge pull request #2089 from zz9pzza/issue_4280_take2
Browse files Browse the repository at this point in the history
issue 4280  getting rid of the counts take two.
  • Loading branch information
sarken committed Apr 26, 2015
2 parents 3c22464 + 8ed3e03 commit c7cfb56
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
6 changes: 6 additions & 0 deletions app/controllers/application_controller.rb
Expand Up @@ -222,6 +222,12 @@ def hide_banner
def set_current_user
User.current_user = logged_in_as_admin? ? current_admin : current_user
@current_user = current_user
unless current_user.nil?
@current_user_subscriptions_count, @current_user_visible_work_count, @current_user_bookmarks_count, @current_user_owned_collections_count, @current_user_challenge_signups_count, @current_user_offer_assignments, @current_user_unposted_works_size=
Rails.cache.fetch("user_menu_counts_#{current_user.id}",
expires_in: ArchiveConfig.USER_MENU_CACHE_TIME,
race_condition_ttl: 5) { "#{current_user.subscriptions.count}, #{current_user.visible_work_count}, #{current_user.bookmarks.count}, #{current_user.owned_collections.count}, #{current_user.challenge_signups.count}, #{current_user.offer_assignments.undefaulted.count + current_user.pinch_hit_assignments.undefaulted.count}, #{current_user.unposted_works.size}" }.split(",").map(&:to_i)
end
end

def load_collection
Expand Down
24 changes: 12 additions & 12 deletions app/views/user_sessions/_greeting.html.erb
Expand Up @@ -6,23 +6,23 @@
<%= link_to ts("Hi, %{current_user}!", :current_user => current_user.login, key: 'header'), user_path(current_user) %>
<ul class="menu" role="menu">
<li><%= span_if_current ts('My Dashboard', key: 'header'), user_path(current_user) %></li>
<% if @current_user.subscriptions.count > 0 %>
<% if @current_user_subscriptions_count > 0 %>
<li><%= span_if_current ts('My Subscriptions', key: 'header'), user_subscriptions_path(current_user) %></li>
<% end %>
<% if @current_user.visible_work_count > 0 %>
<li><%= span_if_current ts("My Works (%{works_number})", key: 'header', :works_number => @current_user.visible_work_count), user_works_path(@current_user) %></li>
<% if @current_user_visible_work_count > 0 %>
<li><%= span_if_current ts("My Works", key: 'header'), user_works_path(@current_user) %></li>
<% end %>
<% if @current_user.bookmarks.count > 0 %>
<li><%= span_if_current ts("My Bookmarks (%{bookmark_number})", key: 'header', :bookmark_number => @current_user.bookmarks.count), user_bookmarks_path(current_user) %></li>
<% if @current_user_bookmarks_count > 0 %>
<li><%= span_if_current ts("My Bookmarks", key: 'header'), user_bookmarks_path(current_user) %></li>
<% end %>
<% if @current_user.owned_collections.count > 0 %>
<li><%= span_if_current ts("My Collections (%{coll_number})", key: 'header', :coll_number => @current_user.owned_collections.count), user_collections_path(current_user) %></li>
<% if @current_user_owned_collections_count > 0 %>
<li><%= span_if_current ts("My Collections", key: 'header'), user_collections_path(current_user) %></li>
<% end %>
<% if @current_user.challenge_signups.count > 0 %>
<li><%= span_if_current ts("My Sign-ups (%{signup_number})", key: 'header', :signup_number => @current_user.challenge_signups.count), user_signups_path(current_user) %></li>
<% if @current_user_challenge_signups_count > 0 %>
<li><%= span_if_current ts("My Sign-ups", key: 'header'), user_signups_path(current_user) %></li>
<% end %>
<% if (@current_user.offer_assignments.undefaulted.count || @current_user.pinch_hit_assignments.undefaulted.count) > 0 %>
<li><%= span_if_current ts("My Assignments (%{assignment_number})", key: 'header', :assignment_number => (@current_user.offer_assignments.undefaulted.count + @current_user.pinch_hit_assignments.undefaulted.count)), user_assignments_path(current_user) %></li>
<% if @current_user_offer_assignments > 0 %>
<li><%= span_if_current ts("My Assignments", key: 'header'), user_assignments_path(current_user) %></li>
<% end %>
<% if @current_user.preference.try(:history_enabled?) %>
<li><%= span_if_current ts('My History', key: 'header'), user_readings_path(current_user) %></li>
Expand All @@ -41,7 +41,7 @@
<ul class="menu" role="menu">
<li><%= link_to ts('New Work', key: 'header'), new_work_path %></li>
<li><%= link_to ts('Import Work', key: 'header'), new_work_path(:import => "true") %></li>
<% if @current_user.unposted_works.size > 0 %>
<% if @current_user_unposted_works_size > 0 %>
<li><%= span_if_current ts('From Draft', key: 'header'), drafts_user_works_path(@current_user) %></li>
<% end %>
</ul>
Expand Down
2 changes: 2 additions & 0 deletions config/config.yml
Expand Up @@ -371,3 +371,5 @@ DUMP_COLLECTION_SEEDS: [
"chromatic_yuletide_2010", "Fandom_Stocking", "yuletidemadness2010", "PornBattleXI",
"Remix2011", "PornBattleXII"
]

USER_MENU_CACHE_TIME: 2.hour

0 comments on commit c7cfb56

Please sign in to comment.