Commit b2c32297 authored by Nick Thomas's avatar Nick Thomas

Merge branch 'ag-fix-clear-session-use' into 'master'

Use read replica for count query without clearing global db load balancing session

See merge request gitlab-org/gitlab!61391
parents 9eff56cb 16f7af69
......@@ -15,14 +15,12 @@ module Analytics
end
def merge_requests_count
# Clear db load balancing session so that primary sticking
# does not apply in case a write has happened recently.
# We want to make sure the load of the following query
# does not land on the primary db.
::Gitlab::Database::LoadBalancing::Session.clear_session
@merge_requests_count ||=
Groups::RecentMergeRequestsCountService.new(@group, @current_user, params).count
# We want to make sure the load of the following query
# lands on the read replica instead of the primary db
current_load_balancing_session.use_replicas_for_read_queries do
count_service.new(@group, @current_user, params).count
end
end
def new_members_count
......@@ -44,5 +42,13 @@ module Analytics
attempt_group_search_optimizations: true,
attempt_project_search_optimizations: true }
end
def current_load_balancing_session
::Gitlab::Database::LoadBalancing::Session.current
end
def count_service
Groups::RecentMergeRequestsCountService
end
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