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
This commit is contained in:
parent
4ade9bf24d
commit
1511999d88
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue