Commit 4680be77 authored by Rajendra Kadam's avatar Rajendra Kadam

Move min max methods to utils usage_data.rb

Add specs for nil methods
parent f0e7574b
......@@ -839,54 +839,6 @@ module Gitlab
count(::Issue.with_prometheus_alert_events, start: issue_minimum_id, finish: issue_maximum_id)
end
def user_minimum_id
strong_memoize(:user_minimum_id) do
::User.minimum(:id)
end
end
def user_maximum_id
strong_memoize(:user_maximum_id) do
::User.maximum(:id)
end
end
def issue_minimum_id
strong_memoize(:issue_minimum_id) do
::Issue.minimum(:id)
end
end
def issue_maximum_id
strong_memoize(:issue_maximum_id) do
::Issue.maximum(:id)
end
end
def deployment_minimum_id
strong_memoize(:deployment_minimum_id) do
::Deployment.minimum(:id)
end
end
def deployment_maximum_id
strong_memoize(:deployment_maximum_id) do
::Deployment.maximum(:id)
end
end
def project_minimum_id
strong_memoize(:project_minimum_id) do
::Project.minimum(:id)
end
end
def project_maximum_id
strong_memoize(:project_maximum_id) do
::Project.maximum(:id)
end
end
def self_monitoring_project
Gitlab::CurrentSettings.self_monitoring_project
end
......
......@@ -36,6 +36,30 @@ module Gitlab
'SELECT ' + args.map {|arg| "(#{arg})" }.join(' + ')
end
def user_minimum_id
end
def user_maximum_id
end
def issue_maximum_id
end
def issue_minimum_id
end
def deployment_minimum_id
end
def deployment_maximum_id
end
def project_minimum_id
end
def project_maximum_id
end
private
def raw_sql(relation, column, distinct = nil)
......
......@@ -209,6 +209,54 @@ module Gitlab
Gitlab::UsageDataCounters::HLLRedisCounter.track_event(event_name.to_s, values: values)
end
def user_minimum_id
strong_memoize(:user_minimum_id) do
::User.minimum(:id)
end
end
def user_maximum_id
strong_memoize(:user_maximum_id) do
::User.maximum(:id)
end
end
def issue_maximum_id
strong_memoize(:issue_maximum_id) do
::Issue.maximum(:id)
end
end
def issue_minimum_id
strong_memoize(:issue_minimum_id) do
::Issue.minimum(:id)
end
end
def deployment_minimum_id
strong_memoize(:deployment_minimum_id) do
::Deployment.minimum(:id)
end
end
def deployment_maximum_id
strong_memoize(:deployment_maximum_id) do
::Deployment.maximum(:id)
end
end
def project_minimum_id
strong_memoize(:project_minimum_id) do
::Project.minimum(:id)
end
end
def project_maximum_id
strong_memoize(:project_maximum_id) do
::Project.maximum(:id)
end
end
private
def prometheus_client(verify:)
......
......@@ -58,4 +58,24 @@ RSpec.describe Gitlab::UsageDataQueries do
.to eq('SELECT (SELECT COUNT("users"."id") FROM "users") + (SELECT COUNT("issues"."id") FROM "issues")')
end
end
describe 'min/max methods' do
it 'returns nil' do
# user min/max
expect(described_class.user_minimum_id).to eq(nil)
expect(described_class.user_maximum_id).to eq(nil)
# issue min/max
expect(described_class.issue_minimum_id).to eq(nil)
expect(described_class.issue_maximum_id).to eq(nil)
# deployment min/max
expect(described_class.deployment_minimum_id).to eq(nil)
expect(described_class.deployment_maximum_id).to eq(nil)
# project min/max
expect(described_class.project_minimum_id).to eq(nil)
expect(described_class.project_maximum_id).to eq(nil)
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