Commit 50145935 authored by Piotr Skorupa's avatar Piotr Skorupa

Refactor caching for metric instrumentation

parent 4b573816
...@@ -42,15 +42,7 @@ module Gitlab ...@@ -42,15 +42,7 @@ module Gitlab
end end
def value def value
key_name = "metric_instrumentation/#{relation.table_name}" start, finish = get_or_cache_batch_ids if batch_query?
start = Rails.cache.fetch("#{key_name}_minimum_id", expires_in: 1.day) do
self.class.start
end
finish = Rails.cache.fetch("#{key_name}_maximum_id", expires_in: 1.day) do
self.class.finish
end
method(self.class.metric_operation) method(self.class.metric_operation)
.call(relation, .call(relation,
...@@ -73,6 +65,10 @@ module Gitlab ...@@ -73,6 +65,10 @@ module Gitlab
private private
def batch_query?
self.class.metric_start.present? && self.class.metric_finish.present?
end
def relation def relation
self.class.metric_relation.call.where(time_constraints) self.class.metric_relation.call.where(time_constraints)
end end
...@@ -89,6 +85,20 @@ module Gitlab ...@@ -89,6 +85,20 @@ module Gitlab
raise "Unknown time frame: #{time_frame} for DatabaseMetric" raise "Unknown time frame: #{time_frame} for DatabaseMetric"
end end
end end
def get_or_cache_batch_ids
key_name = "metric_instrumentation/#{relation.table_name}"
start = Rails.cache.fetch("#{key_name}_minimum_id", expires_in: 1.day) do
self.class.start
end
finish = Rails.cache.fetch("#{key_name}_maximum_id", expires_in: 1.day) do
self.class.finish
end
[start, finish]
end
end end
end 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