Skip to content

Optimize notes and suggestion counters

Fix the queries for both monthly, and all-times version of the queries with batch counters enabled.

  • Notes is one of the large tables with with 230 millions rows on gitlab.com.

# 1 Locations https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/lib/ee/gitlab/usage_data.rb
time_period = { }

distinct_count(::Note.where(time_period), :author_id),
distinct_count(::Note.with_suggestions.where(time_period), :author_id)

# 2 Locations https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/lib/ee/gitlab/usage_data.rb
time_period = { created_at: 28.days.ago..Time.current }

distinct_count(::Note.where(time_period), :author_id),
distinct_count(::Note.with_suggestions.where(time_period), :author_id)

Guide to optimize the counter

Edited by Alper Akgun