Commit b359579d authored by Andreas Brandl's avatar Andreas Brandl

Merge branch '334761-index-historical-data-on-recorded-at' into 'master'

Add index on historical_data (recorded_at) to improve queries

See merge request gitlab-org/gitlab!68435
parents f506249b 9d3cc94d
# frozen_string_literal: true
class IndexHistoricalDataOnRecordedAt < ActiveRecord::Migration[6.1]
include Gitlab::Database::MigrationHelpers
INDEX_NAME = 'index_historical_data_on_recorded_at'
disable_ddl_transaction!
def up
add_concurrent_index :historical_data, :recorded_at, name: INDEX_NAME
end
def down
remove_concurrent_index_by_name :historical_data, INDEX_NAME
end
end
ebf0c2a7b0563dafa562136a0758baf631db92c0ce33f7200da24092f1eb2930
\ No newline at end of file
......@@ -24135,6 +24135,8 @@ CREATE UNIQUE INDEX index_group_wiki_repositories_on_disk_path ON group_wiki_rep
CREATE INDEX index_group_wiki_repositories_on_shard_id ON group_wiki_repositories USING btree (shard_id);
CREATE INDEX index_historical_data_on_recorded_at ON historical_data USING btree (recorded_at);
CREATE UNIQUE INDEX index_http_integrations_on_active_and_project_and_endpoint ON alert_management_http_integrations USING btree (active, project_id, endpoint_identifier) WHERE active;
CREATE INDEX index_identities_on_saml_provider_id ON identities USING btree (saml_provider_id) WHERE (saml_provider_id IS NOT NULL);
......@@ -5,8 +5,6 @@ class HistoricalData < ApplicationRecord
# HistoricalData.during((Time.current - 1.year)..Time.current).average(:active_user_count)
scope :during, ->(range) { where(recorded_at: range) }
# HistoricalData.up_until(Time.current - 1.month).average(:active_user_count)
scope :up_until, ->(timestamp) { where("recorded_at <= :timestamp", timestamp: timestamp) }
class << self
def track!
......
......@@ -15,12 +15,6 @@ RSpec.describe HistoricalData do
end
end
describe ".up_until" do
it "returns the historical data up until the specified date" do
expect(described_class.up_until(Date.new(2014, 6, 1)).average(:active_user_count)).to eq(350)
end
end
describe ".track!" do
before do
allow(User).to receive(:billable).and_return([1, 2, 3, 4, 5])
......
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