diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-01-23 04:51:35 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-01-23 06:02:06 +0300 |
commit | 12fa3e1b94de7232fe0337033f9dbc600248d0ec (patch) | |
tree | bc25ef4d0366b2cb49d560910973903db1cc69eb | |
parent | 98423148c5cf6de759cba74a78ade7b7c1da81ed (diff) |
Faster autocomplete for users/issues/emojiis
Instead of loading all issues and merge requests we load only open one.
This will reduce time load for autocomplete resources significantly
-rw-r--r-- | app/controllers/projects_controller.rb | 15 | ||||
-rw-r--r-- | app/services/projects/autocomplete_service.rb | 15 |
2 files changed, 27 insertions, 3 deletions
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index e541b6fd872..7fc283ef3d4 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -101,11 +101,20 @@ class ProjectsController < ApplicationController def autocomplete_sources note_type = params['type'] note_id = params['type_id'] + autocomplete = ::Projects::AutocompleteService.new(@project) participants = ::Projects::ParticipantsService.new(@project).execute(note_type, note_id) + + emojis = Emoji.names.map do |e| + { + name: e, + path: view_context.image_url("emoji/#{e}.png") + } + end + @suggestions = { - emojis: Emoji.names.map { |e| { name: e, path: view_context.image_url("emoji/#{e}.png") } }, - issues: @project.issues.select([:iid, :title, :description]), - mergerequests: @project.merge_requests.select([:iid, :title, :description]), + emojis: emojis, + issues: autocomplete.issues, + mergerequests: autocomplete.merge_requests, members: participants } diff --git a/app/services/projects/autocomplete_service.rb b/app/services/projects/autocomplete_service.rb new file mode 100644 index 00000000000..09fc25cc1b3 --- /dev/null +++ b/app/services/projects/autocomplete_service.rb @@ -0,0 +1,15 @@ +module Projects + class AutocompleteService < BaseService + def initialize(project) + @project = project + end + + def issues + @project.issues.opened.select([:iid, :title, :description]) + end + + def merge_requests + @project.merge_requests.opened.select([:iid, :title, :description]) + end + end +end |