Commit fd9377fa authored by Gabriel Mazetto's avatar Gabriel Mazetto

Added method to re-populating SiteStatitiscs counter

parent 76cd1dd6
......@@ -49,7 +49,7 @@ def self.with_statistics_available(raw_attribute)
#
# @return [SiteStatistic] record with tracked information
def self.fetch
SiteStatistic.transaction(requires_new: true) do
transaction(requires_new: true) do
SiteStatistic.first_or_create!
end
rescue ActiveRecord::RecordNotUnique
......@@ -73,4 +73,18 @@ def self.reset_column_information
super
end
def self.recalculate_counters!
transaction do
# see https://gitlab.com/gitlab-org/gitlab-ce/issues/48967
ActiveRecord::Base.connection.execute('SET LOCAL statement_timeout TO 0') if Gitlab::Database.postgresql?
self.update_all('repositories_count = (SELECT COUNT(*) FROM projects)')
end
transaction do
# see https://gitlab.com/gitlab-org/gitlab-ce/issues/48967
ActiveRecord::Base.connection.execute('SET LOCAL statement_timeout TO 0') if Gitlab::Database.postgresql?
self.update_all('wikis_count = (SELECT COUNT(*) FROM project_features WHERE wiki_access_level != 0)')
end
end
end
......@@ -80,4 +80,16 @@
end
end
end
describe '.recalculate_counters!' do
it 'recalculates existing counters' do
create(:project)
described_class.fetch.update(repositories_count: 0, wikis_count: 0)
described_class.recalculate_counters!
expect(described_class.fetch.repositories_count).to eq(1)
expect(described_class.fetch.wikis_count).to eq(1)
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