summaryrefslogtreecommitdiff
path: root/app/helpers/count_helper.rb
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2018-05-15 23:06:55 -0700
committerStan Hu <stanhu@gmail.com>2018-05-16 08:27:48 -0700
commite38938b332ca751dfc5e784f242d620016e8ca43 (patch)
tree439a6672547ba9d50d995e7717df28ab6ded89fd /app/helpers/count_helper.rb
parent0288e2525fbe2bc226726b5289fc6e5b3a949da2 (diff)
downloadgitlab-ce-e38938b332ca751dfc5e784f242d620016e8ca43.tar.gz
Fix Error 500 viewing admin page due to statement timeouts
Uses PostgreSQL tuple estimates to provide a much faster yet approximate count. See https://wiki.postgresql.org/wiki/Slow_Counting for more details. We only use this fast method if the table has been analyzed or vacuumed within the last hour. Closes #46255
Diffstat (limited to 'app/helpers/count_helper.rb')
-rw-r--r--app/helpers/count_helper.rb5
1 files changed, 5 insertions, 0 deletions
diff --git a/app/helpers/count_helper.rb b/app/helpers/count_helper.rb
new file mode 100644
index 00000000000..24ee62e68ba
--- /dev/null
+++ b/app/helpers/count_helper.rb
@@ -0,0 +1,5 @@
+module CountHelper
+ def approximate_count_with_delimiters(model)
+ number_with_delimiter(Gitlab::Database::Count.approximate_count(model))
+ end
+end