f30089075f
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.
66 lines
1.2 KiB
Ruby
66 lines
1.2 KiB
Ruby
class Admin::HooksController < Admin::ApplicationController
|
|
include HooksExecution
|
|
|
|
before_action :hook_logs, only: :edit
|
|
|
|
def index
|
|
@hooks = SystemHook.all
|
|
@hook = SystemHook.new
|
|
end
|
|
|
|
def create
|
|
@hook = SystemHook.new(hook_params.to_h)
|
|
|
|
if @hook.save
|
|
redirect_to admin_hooks_path, notice: 'Hook was successfully created.'
|
|
else
|
|
@hooks = SystemHook.all
|
|
render :index
|
|
end
|
|
end
|
|
|
|
def edit
|
|
end
|
|
|
|
def update
|
|
if hook.update_attributes(hook_params)
|
|
flash[:notice] = 'System hook was successfully updated.'
|
|
redirect_to admin_hooks_path
|
|
else
|
|
render 'edit'
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
hook.destroy
|
|
|
|
redirect_to admin_hooks_path, status: 302
|
|
end
|
|
|
|
def test
|
|
result = TestHooks::SystemService.new(hook, current_user, params[:trigger]).execute
|
|
|
|
set_hook_execution_notice(result)
|
|
|
|
redirect_back_or_default
|
|
end
|
|
|
|
private
|
|
|
|
def hook
|
|
@hook ||= SystemHook.find(params[:id])
|
|
end
|
|
|
|
def hook_logs
|
|
@hook_logs ||= hook.web_hook_logs.recent.page(params[:page])
|
|
end
|
|
|
|
def hook_params
|
|
params.require(:hook).permit(
|
|
:enable_ssl_verification,
|
|
:token,
|
|
:url,
|
|
*SystemHook.triggers.values
|
|
)
|
|
end
|
|
end
|