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
# See https://gitlab.com/gitlab-org/gitlab/-/merge_requests/41091
class UsageDataQueries < UsageData
class << self
def count(relation, column = nil, *rest)
def count(relation, column = nil, *args, **kwargs)
raw_sql(relation, column)
end
def distinct_count(relation, column = nil, *rest)
def distinct_count(relation, column = nil, *args, **kwargs)
raw_sql(relation, column, :distinct)
end
......@@ -21,14 +21,14 @@ module Gitlab
end
end
def sum(relation, column, *rest)
def sum(relation, column, *args, **kwargs)
relation.select(relation.all.table[column].sum).to_sql
end
# For estimated distinct count use exact query instead of hll
# buckets query, because it can't be used to obtain estimations without
# 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)
end
......
......@@ -11,12 +11,24 @@ RSpec.describe Gitlab::UsageDataQueries do
it 'returns the raw SQL' do
expect(described_class.count(User)).to start_with('SELECT COUNT("users"."id") FROM "users"')
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
describe '.distinct_count' 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"')
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
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