Commit 8c3e6987 authored by Lucas Deschamps's avatar Lucas Deschamps

Navigation bar issuables counters reflects dashboard issuables counters

parent f27f9803
......@@ -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
......
......@@ -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
......
---
title: Navigation bar issuables counters reflects dashboard issuables counters
merge_request:
author: Lucas Deschamps
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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment