From bffe0d6325710e89e405390f4da297fb12fdc314 Mon Sep 17 00:00:00 2001 From: Josh Frye Date: Tue, 31 May 2016 08:58:11 -0400 Subject: Cache assigned merge request count. Closes #18036 --- app/models/user.rb | 6 ++++++ app/views/layouts/nav/_dashboard.html.haml | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'app') diff --git a/app/models/user.rb b/app/models/user.rb index 15b6cbc2255..8dde01bf355 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -776,6 +776,12 @@ class User < ActiveRecord::Base notification_settings.find_or_initialize_by(source: source) end + def assigned_open_merge_request_count + Rails.cache.fetch(['users', id, 'assigned_open_merge_request_count'], expires_in: 60) do + assigned_merge_requests.opened.count + end + end + private def projects_union diff --git a/app/views/layouts/nav/_dashboard.html.haml b/app/views/layouts/nav/_dashboard.html.haml index 43532b0c155..e14ae850fcc 100644 --- a/app/views/layouts/nav/_dashboard.html.haml +++ b/app/views/layouts/nav/_dashboard.html.haml @@ -36,7 +36,7 @@ = icon('tasks fw') %span Merge Requests - %span.count= number_with_delimiter(current_user.assigned_merge_requests.opened.count) + %span.count= number_with_delimiter(current_user.assigned_open_merge_request_count) = nav_link(controller: :snippets) do = link_to dashboard_snippets_path, title: 'Snippets' do = icon('clipboard fw') -- cgit v1.2.3