summaryrefslogtreecommitdiff
path: root/app/models/site_statistic.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/site_statistic.rb')
-rw-r--r--app/models/site_statistic.rb16
1 files changed, 15 insertions, 1 deletions
diff --git a/app/models/site_statistic.rb b/app/models/site_statistic.rb
index daac1c57db9..2530a9d8b8e 100644
--- a/app/models/site_statistic.rb
+++ b/app/models/site_statistic.rb
@@ -49,7 +49,7 @@ class SiteStatistic < ActiveRecord::Base
#
# @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 @@ class SiteStatistic < ActiveRecord::Base
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