Commit 7f27a35e authored by Yorick Peterse's avatar Yorick Peterse

Merge branch 'zj-slow-service-fetch' into 'master'

Improve performance of triggered chat commands

See merge request !8876
parents 09567e93 9bd424a3
---
title: Improve performance of slash commands
merge_request: 8876
author:
...@@ -661,6 +661,14 @@ module API ...@@ -661,6 +661,14 @@ module API
end end
trigger_services.each do |service_slug, settings| 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 params do
requires :id, type: String, desc: 'The ID of a project' requires :id, type: String, desc: 'The ID of a project'
end end
...@@ -679,9 +687,8 @@ module API ...@@ -679,9 +687,8 @@ module API
# This is not accurate, but done to prevent leakage of the project names # This is not accurate, but done to prevent leakage of the project names
not_found!('Service') unless project not_found!('Service') unless project
service = project.find_or_initialize_service(service_slug.underscore) service = chat_command_service(project, service_slug, params)
result = service.try(:trigger, params)
result = service.try(:active?) && service.try(:trigger, params)
if result if result
status result[:status] || 200 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