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
diff options
context:
space:
mode:
authorZ.J. van de Weg <git@zjvandeweg.nl>2017-01-30 14:29:55 +0300
committerZ.J. van de Weg <git@zjvandeweg.nl>2017-01-30 15:38:36 +0300
commit9bd424a3fd2829f92329f22365dd2f7105d67eb5 (patch)
treeb25f85e177ef1fed068a696ff5279da496f99bae /lib/api/services.rb
parent067ce273a592abbcc7d9e417a5466ba113882dca (diff)
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.
Diffstat (limited to 'lib/api/services.rb')
-rw-r--r--lib/api/services.rb13
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/api/services.rb b/lib/api/services.rb
index a0abec49438..1456fe4688b 100644
--- a/lib/api/services.rb
+++ b/lib/api/services.rb
@@ -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