Commit cfcf5460 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'fix_navigation_bar_issuables_counters' into 'master'

Navigation bar issuables counters reflects dashboard issuables counters

Adds a 2 minute cache on navigation bar issuables counters.

The counters on dashboard/issues and dashboard/merge_requests are cached while the navigation bar issuables counters were not. Users read incoherent issuables count throughout the application.

Fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/23882

See merge request !7368
parents 05be65f3 3d13096f
......@@ -136,8 +136,19 @@ module IssuablesHelper
html.html_safe
end
def cached_assigned_issuables_count(assignee, issuable_type, state)
cache_key = hexdigest(['assigned_issuables_count', assignee.id, issuable_type, state].join('-'))
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.public_send("assigned_#{issuable_type}").public_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: 7368
author: Lucas Deschamps
require 'spec_helper'
describe 'Navigation bar counter', feature: true, js: true, caching: true do
let(:user) { create(:user) }
let(:project) { create(:empty_project, namespace: user.namespace) }
let(:issue) { create(:issue, project: project) }
let(:merge_request) { create(:merge_request, source_project: project) }
before do
issue.update(assignee: user)
merge_request.update(assignee: user)
login_as(user)
end
it 'reflects dashboard issues count' do
visit issues_dashboard_path
expect_counters('issues', '1')
issue.update(assignee: nil)
visit issues_dashboard_path
expect_counters('issues', '1')
end
it 'reflects dashboard merge requests count' do
visit merge_requests_dashboard_path
expect_counters('merge_requests', '1')
merge_request.update(assignee: nil)
visit merge_requests_dashboard_path
expect_counters('merge_requests', '1')
end
def expect_counters(issuable_type, count)
dashboard_count = find('li.active span.badge')
nav_count = find(".dashboard-shortcuts-#{issuable_type} span.count")
expect(nav_count).to have_content(count)
expect(dashboard_count).to have_content(count)
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