diff options
author | Nick Thomas <nick@gitlab.com> | 2018-08-28 11:03:39 +0000 |
---|---|---|
committer | Nick Thomas <nick@gitlab.com> | 2018-08-28 11:03:39 +0000 |
commit | ad985d8d6be8274a8ea35808a94354a333cb8e8c (patch) | |
tree | 22f2b7ff9908a43c58b36137d82ae89171fbb993 /db | |
parent | 270c7b6f78cb09c23f14be550ca054da6978002b (diff) | |
parent | 414c54cec2e6e3b9c6e4cf003b78a637464b6d8b (diff) | |
download | gitlab-ce-ad985d8d6be8274a8ea35808a94354a333cb8e8c.tar.gz |
Merge branch '50441-high-number-of-statement-timeouts-in-groupdestroyworker-due-to-sitestatistics' into 'master'
Resolve "High number of statement timeouts in GroupDestroyWorker due to SiteStatistics"
Closes #50441
See merge request gitlab-org/gitlab-ce!21366
Diffstat (limited to 'db')
-rw-r--r-- | db/post_migrate/20180826111825_recalculate_site_statistics.rb | 27 | ||||
-rw-r--r-- | db/schema.rb | 2 |
2 files changed, 28 insertions, 1 deletions
diff --git a/db/post_migrate/20180826111825_recalculate_site_statistics.rb b/db/post_migrate/20180826111825_recalculate_site_statistics.rb new file mode 100644 index 00000000000..741035a444f --- /dev/null +++ b/db/post_migrate/20180826111825_recalculate_site_statistics.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +class RecalculateSiteStatistics < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + transaction do + execute('SET LOCAL statement_timeout TO 0') if Gitlab::Database.postgresql? # see https://gitlab.com/gitlab-org/gitlab-ce/issues/48967 + + execute("UPDATE site_statistics SET repositories_count = (SELECT COUNT(*) FROM projects)") + end + + transaction do + execute('SET LOCAL statement_timeout TO 0') if Gitlab::Database.postgresql? # see https://gitlab.com/gitlab-org/gitlab-ce/issues/48967 + + execute("UPDATE site_statistics SET wikis_count = (SELECT COUNT(*) FROM project_features WHERE wiki_access_level != 0)") + end + end + + def down + # No downside in keeping the counter up-to-date + end +end diff --git a/db/schema.rb b/db/schema.rb index 380d4e49ddf..cb8f90efded 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20180816193530) do +ActiveRecord::Schema.define(version: 20180826111825) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" |