summaryrefslogtreecommitdiff
path: root/lib/tasks
diff options
context:
space:
mode:
authorGabriel Mazetto <brodock@gmail.com>2018-08-15 01:40:29 +0200
committerGabriel Mazetto <brodock@gmail.com>2018-08-16 21:31:19 +0200
commit1a54986c166fb13a6a27afcafaa055e1a1749e38 (patch)
tree46e6f80a4726f3402bd4b5de28d55c8f83caf9f1 /lib/tasks
parent696a5fce687364ec718eeef44d923a686c9e1624 (diff)
downloadgitlab-ce-1a54986c166fb13a6a27afcafaa055e1a1749e38.tar.gz
Refactor SiteStatistics to extract refresh logic into a rake task
Diffstat (limited to 'lib/tasks')
-rw-r--r--lib/tasks/gitlab/site_statistics.rake23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/tasks/gitlab/site_statistics.rake b/lib/tasks/gitlab/site_statistics.rake
new file mode 100644
index 00000000000..7d24ec72a9d
--- /dev/null
+++ b/lib/tasks/gitlab/site_statistics.rake
@@ -0,0 +1,23 @@
+namespace :gitlab do
+ desc "GitLab | Refresh Site Statistics counters"
+ task refresh_site_statistics: :environment do
+ puts 'Updating Site Statistics counters: '
+
+ print '* Repositories... '
+ SiteStatistic.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?
+ SiteStatistic.update_all('repositories_count = (SELECT COUNT(*) FROM projects)')
+ end
+ puts 'OK!'.color(:green)
+
+ print '* Wikis... '
+ SiteStatistic.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?
+ SiteStatistic.update_all('wikis_count = (SELECT COUNT(*) FROM project_features WHERE wiki_access_level != 0)')
+ end
+ puts 'OK!'.color(:green)
+ puts
+ end
+end