Commit 9a281aa6 authored by Aakriti Gupta's avatar Aakriti Gupta

Use read replica for count query

- This removes the incorrect clearing of the
global database load balancing session
parent 0efe495c
......@@ -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
# does not land 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