Commit e34ac67c authored by Alper Akgun's avatar Alper Akgun

Merge branch '325884-usage-data-count-start-finish-problems' into 'master'

Fix usage data count start/finish export issue

See merge request gitlab-org/gitlab!57403
parents 0038d3a2 7a943c60
---
title: Fix usage data count start/finish export issue
merge_request: 57403
author:
type: fixed
...@@ -5,11 +5,11 @@ module Gitlab ...@@ -5,11 +5,11 @@ module Gitlab
# See https://gitlab.com/gitlab-org/gitlab/-/merge_requests/41091 # See https://gitlab.com/gitlab-org/gitlab/-/merge_requests/41091
class UsageDataQueries < UsageData class UsageDataQueries < UsageData
class << self class << self
def count(relation, column = nil, *rest) def count(relation, column = nil, *args, **kwargs)
raw_sql(relation, column) raw_sql(relation, column)
end end
def distinct_count(relation, column = nil, *rest) def distinct_count(relation, column = nil, *args, **kwargs)
raw_sql(relation, column, :distinct) raw_sql(relation, column, :distinct)
end end
...@@ -21,14 +21,14 @@ module Gitlab ...@@ -21,14 +21,14 @@ module Gitlab
end end
end end
def sum(relation, column, *rest) def sum(relation, column, *args, **kwargs)
relation.select(relation.all.table[column].sum).to_sql relation.select(relation.all.table[column].sum).to_sql
end end
# For estimated distinct count use exact query instead of hll # For estimated distinct count use exact query instead of hll
# buckets query, because it can't be used to obtain estimations without # buckets query, because it can't be used to obtain estimations without
# supplementary ruby code present in Gitlab::Database::PostgresHll::BatchDistinctCounter # supplementary ruby code present in Gitlab::Database::PostgresHll::BatchDistinctCounter
def estimate_batch_distinct_count(relation, column = nil, *rest) def estimate_batch_distinct_count(relation, column = nil, *args, **kwargs)
raw_sql(relation, column, :distinct) raw_sql(relation, column, :distinct)
end end
......
...@@ -11,12 +11,24 @@ RSpec.describe Gitlab::UsageDataQueries do ...@@ -11,12 +11,24 @@ RSpec.describe Gitlab::UsageDataQueries do
it 'returns the raw SQL' do it 'returns the raw SQL' do
expect(described_class.count(User)).to start_with('SELECT COUNT("users"."id") FROM "users"') expect(described_class.count(User)).to start_with('SELECT COUNT("users"."id") FROM "users"')
end end
it 'does not mix a nil column with keyword arguments' do
expect(described_class).to receive(:raw_sql).with(User, nil)
described_class.count(User, start: 1, finish: 2)
end
end end
describe '.distinct_count' do describe '.distinct_count' do
it 'returns the raw SQL' do it 'returns the raw SQL' do
expect(described_class.distinct_count(Issue, :author_id)).to eq('SELECT COUNT(DISTINCT "issues"."author_id") FROM "issues"') expect(described_class.distinct_count(Issue, :author_id)).to eq('SELECT COUNT(DISTINCT "issues"."author_id") FROM "issues"')
end end
it 'does not mix a nil column with keyword arguments' do
expect(described_class).to receive(:raw_sql).with(Issue, nil, :distinct)
described_class.distinct_count(Issue, nil, start: 1, finish: 2)
end
end end
describe '.redis_usage_data' do describe '.redis_usage_data' 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