diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2018-06-28 16:34:31 +0300 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2018-07-03 15:24:17 +0300 |
commit | f30089075fabfbac45c6382c0a2717bbb682734e (patch) | |
tree | 8864a5843ed5f6d1e0e079194def14682b1a9824 /app/models/hooks | |
parent | f25cdea64d69a97f31719622f9dead3de1ea0e11 (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/models/hooks')
-rw-r--r-- | app/models/hooks/web_hook_log.rb | 5 |
1 files changed, 5 insertions, 0 deletions
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 |