diff options
author | Lucas Deschamps <lucasdchamps@gmail.com> | 2016-11-09 07:59:51 +0100 |
---|---|---|
committer | Lucas Deschamps <lucasdchamps@gmail.com> | 2016-11-16 09:44:49 +0100 |
commit | 8c3e6987d931847b72752dfcac4215dbdc47fd88 (patch) | |
tree | 0ef45e3d9ffc330d9d25bc45f4720189b14ef879 | |
parent | f27f9803833f72d7f62534c195539dcdef2e3ccd (diff) | |
download | gitlab-ce-8c3e6987d931847b72752dfcac4215dbdc47fd88.tar.gz |
Navigation bar issuables counters reflects dashboard issuables counters
-rw-r--r-- | app/helpers/issuables_helper.rb | 11 | ||||
-rw-r--r-- | app/views/layouts/nav/_dashboard.html.haml | 4 | ||||
-rw-r--r-- | changelogs/unreleased/fix_navigation_bar_issuables_counters.yml | 4 | ||||
-rw-r--r-- | spec/features/dashboard/issuables_counter_spec.rb | 33 |
4 files changed, 50 insertions, 2 deletions
diff --git a/app/helpers/issuables_helper.rb b/app/helpers/issuables_helper.rb index 8127c3f3ee3..22311267860 100644 --- a/app/helpers/issuables_helper.rb +++ b/app/helpers/issuables_helper.rb @@ -141,8 +141,19 @@ module IssuablesHelper html.html_safe end + def cached_assigned_issuables_count(assignee, issuable_type, state) + cache_key = "#{assignee.id}_#{issuable_type}_#{state}" + Rails.cache.fetch(cache_key, expires_in: 2.minutes) do + assigned_issuables_count(assignee, issuable_type, state) + end + end + private + def assigned_issuables_count(assignee, issuable_type, state) + assignee.send("assigned_#{issuable_type}").send(state).count + end + def sidebar_gutter_collapsed? cookies[:collapsed_gutter] == 'true' end diff --git a/app/views/layouts/nav/_dashboard.html.haml b/app/views/layouts/nav/_dashboard.html.haml index a0356feef95..2a6d9cda379 100644 --- a/app/views/layouts/nav/_dashboard.html.haml +++ b/app/views/layouts/nav/_dashboard.html.haml @@ -26,12 +26,12 @@ = link_to assigned_issues_dashboard_path, title: 'Issues', class: 'dashboard-shortcuts-issues' do %span Issues - %span.count= number_with_delimiter(current_user.assigned_issues.opened.count) + %span.count= number_with_delimiter(cached_assigned_issuables_count(current_user, :issues, :opened)) = nav_link(path: 'dashboard#merge_requests') do = link_to assigned_mrs_dashboard_path, title: 'Merge Requests', class: 'dashboard-shortcuts-merge_requests' do %span Merge Requests - %span.count= number_with_delimiter(current_user.assigned_merge_requests.opened.count) + %span.count= number_with_delimiter(cached_assigned_issuables_count(current_user, :merge_requests, :opened)) = nav_link(controller: 'dashboard/snippets') do = link_to dashboard_snippets_path, title: 'Snippets' do %span diff --git a/changelogs/unreleased/fix_navigation_bar_issuables_counters.yml b/changelogs/unreleased/fix_navigation_bar_issuables_counters.yml new file mode 100644 index 00000000000..c66f191a2d0 --- /dev/null +++ b/changelogs/unreleased/fix_navigation_bar_issuables_counters.yml @@ -0,0 +1,4 @@ +--- +title: Navigation bar issuables counters reflects dashboard issuables counters +merge_request: +author: Lucas Deschamps diff --git a/spec/features/dashboard/issuables_counter_spec.rb b/spec/features/dashboard/issuables_counter_spec.rb new file mode 100644 index 00000000000..699bc102790 --- /dev/null +++ b/spec/features/dashboard/issuables_counter_spec.rb @@ -0,0 +1,33 @@ +require 'spec_helper' + +describe 'Navigation bar counter', feature: true, js: true, caching: true do + let(:user) { create(:user) } + let(:project) { create(:project, namespace: user.namespace) } + + before do + login_as(user) + visit issues_dashboard_path + end + + it 'reflects dashboard issues count' do + create(:issue, project: project, assignee: user) + visit issues_dashboard_path + + dashboard_count = find('li.active span.badge') + nav_count = find('.dashboard-shortcuts-issues span.count') + + expect(dashboard_count).to have_content('0') + expect(nav_count).to have_content('0') + end + + it 'reflects dashboard merge requests count' do + create(:merge_request, assignee: user) + visit merge_requests_dashboard_path + + dashboard_count = find('li.active span.badge') + nav_count = find('.dashboard-shortcuts-merge_requests span.count') + + expect(dashboard_count).to have_content('0') + expect(nav_count).to have_content('0') + end +end |