Commit c8ab34d8 authored by Alex Kalderimis's avatar Alex Kalderimis

Merge branch '300150-cache-search-tab-counters' into 'master'

Cache /search/count requests in the browser

See merge request gitlab-org/gitlab!55036
parents b6a4a948 7c9da21e
......@@ -49,6 +49,12 @@ class SearchController < ApplicationController
scope = search_service.scope
count = search_service.search_results.formatted_count(scope)
# Users switching tabs will keep fetching the same tab counts so it's a
# good idea to cache in their browser just for a short time. They can still
# clear cache if they are seeing an incorrect count but inaccurate count is
# not such a bad thing.
expires_in 1.minute
render json: { count: count }
end
......
---
title: Cache /search/count requests in the browser
merge_request: 55036
author:
type: performance
......@@ -252,6 +252,14 @@ RSpec.describe SearchController do
get :count, params: { search: 'hello' }
end.to raise_error(ActionController::ParameterMissing)
end
it 'sets private cache control headers' do
get :count, params: { search: 'hello', scope: 'projects' }
expect(response).to have_gitlab_http_status(:ok)
expect(response.headers['Cache-Control']).to include('max-age=60, private')
end
end
describe 'GET #autocomplete' do
......
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