Commit 9bd424a3 authored by Z.J. van de Weg's avatar Z.J. van de Weg

Improve performance of triggered chat commands

When the trigger endpoint is called, it has to find the right service
for the given project. However, the old implementation did much more.

For example, it build a list of the missing services on this project.
This whole process took about 750ms _each time_. The current
implementation is expected to perform 10x better, as it only searches in
the current projects services. Given the service has to be configured
anyway, this can be done.
parent 067ce273
---
title: Improve performance of slash commands
merge_request: 8876
author:
......@@ -661,6 +661,14 @@ module API
end
trigger_services.each do |service_slug, settings|
helpers do
def chat_command_service(project, service_slug, params)
project.services.active.where(template: false).find do |service|
service.try(:token) == params[:token] && service.to_param == service_slug.underscore
end
end
end
params do
requires :id, type: String, desc: 'The ID of a project'
end
......@@ -679,9 +687,8 @@ module API
# This is not accurate, but done to prevent leakage of the project names
not_found!('Service') unless project
service = project.find_or_initialize_service(service_slug.underscore)
result = service.try(:active?) && service.try(:trigger, params)
service = chat_command_service(project, service_slug, params)
result = service.try(:trigger, params)
if result
status result[:status] || 200
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment