Commit 12fa3e1b authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

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
parent 98423148
......@@ -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
}
......
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
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