Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2018-06-28 16:34:31 +0300
committerYorick Peterse <yorickpeterse@gmail.com>2018-07-03 15:24:17 +0300
commitf30089075fabfbac45c6382c0a2717bbb682734e (patch)
tree8864a5843ed5f6d1e0e079194def14682b1a9824 /app
parentf25cdea64d69a97f31719622f9dead3de1ea0e11 (diff)
Fixed pagination of web hook logs
For reasons unknown, the logs of a web hook were paginated in memory. This would result in the "Edit" page of a web hook timing out once it has more than a few thousand log entries. This commit makes the following changes: 1. We use LIMIT/OFFSET to paginate the data, instead of doing this in memory. 2. We limit the logs to the last two days, just like the documentation says (instead of retrieving everything). 3. We change the indexes on "web_hook_logs" so the query to get the data can perform a backwards index scan, without the need for a Filter. These changes combined ensure that Projects::HooksController#edit no longer times out.
Diffstat (limited to 'app')
-rw-r--r--app/controllers/admin/hooks_controller.rb3
-rw-r--r--app/controllers/projects/hooks_controller.rb3
-rw-r--r--app/models/hooks/web_hook_log.rb5
3 files changed, 7 insertions, 4 deletions
diff --git a/app/controllers/admin/hooks_controller.rb b/app/controllers/admin/hooks_controller.rb
index fb788c47ef1..6944857bd33 100644
--- a/app/controllers/admin/hooks_controller.rb
+++ b/app/controllers/admin/hooks_controller.rb
@@ -52,8 +52,7 @@ class Admin::HooksController < Admin::ApplicationController
end
def hook_logs
- @hook_logs ||=
- Kaminari.paginate_array(hook.web_hook_logs.order(created_at: :desc)).page(params[:page])
+ @hook_logs ||= hook.web_hook_logs.recent.page(params[:page])
end
def hook_params
diff --git a/app/controllers/projects/hooks_controller.rb b/app/controllers/projects/hooks_controller.rb
index dd7aa1a67b9..6800d742b0a 100644
--- a/app/controllers/projects/hooks_controller.rb
+++ b/app/controllers/projects/hooks_controller.rb
@@ -58,8 +58,7 @@ class Projects::HooksController < Projects::ApplicationController
end
def hook_logs
- @hook_logs ||=
- Kaminari.paginate_array(hook.web_hook_logs.order(created_at: :desc)).page(params[:page])
+ @hook_logs ||= hook.web_hook_logs.recent.page(params[:page])
end
def hook_params
diff --git a/app/models/hooks/web_hook_log.rb b/app/models/hooks/web_hook_log.rb
index e72c125fb69..59a1f2aed69 100644
--- a/app/models/hooks/web_hook_log.rb
+++ b/app/models/hooks/web_hook_log.rb
@@ -7,6 +7,11 @@ class WebHookLog < ActiveRecord::Base
validates :web_hook, presence: true
+ def self.recent
+ where('created_at >= ?', 2.days.ago.beginning_of_day)
+ .order(created_at: :desc)
+ end
+
def success?
response_status =~ /^2/
end