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.
72 lines
1.5 KiB
Ruby
72 lines
1.5 KiB
Ruby
class Projects::HooksController < Projects::ApplicationController
|
|
include HooksExecution
|
|
|
|
# Authorize
|
|
before_action :authorize_admin_project!
|
|
before_action :hook_logs, only: :edit
|
|
|
|
respond_to :html
|
|
|
|
layout "project_settings"
|
|
|
|
def index
|
|
redirect_to project_settings_integrations_path(@project)
|
|
end
|
|
|
|
def create
|
|
@hook = @project.hooks.new(hook_params)
|
|
@hook.save
|
|
|
|
unless @hook.valid?
|
|
@hooks = @project.hooks.select(&:persisted?)
|
|
flash[:alert] = @hook.errors.full_messages.join.html_safe
|
|
end
|
|
|
|
redirect_to project_settings_integrations_path(@project)
|
|
end
|
|
|
|
def edit
|
|
end
|
|
|
|
def update
|
|
if hook.update_attributes(hook_params)
|
|
flash[:notice] = 'Hook was successfully updated.'
|
|
redirect_to project_settings_integrations_path(@project)
|
|
else
|
|
render 'edit'
|
|
end
|
|
end
|
|
|
|
def test
|
|
result = TestHooks::ProjectService.new(hook, current_user, params[:trigger]).execute
|
|
|
|
set_hook_execution_notice(result)
|
|
|
|
redirect_back_or_default(default: { action: 'index' })
|
|
end
|
|
|
|
def destroy
|
|
hook.destroy
|
|
|
|
redirect_to project_settings_integrations_path(@project), status: 302
|
|
end
|
|
|
|
private
|
|
|
|
def hook
|
|
@hook ||= @project.hooks.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,
|
|
*ProjectHook.triggers.values
|
|
)
|
|
end
|
|
end
|