Commit 7934e400 authored by Valery Sizov's avatar Valery Sizov

[Multiple issue assignees] Elasticsearch for multiple assignees in issue

parent aba54cae
......@@ -17,7 +17,14 @@ module Elastic
indexes :state, type: :text
indexes :project_id, type: :integer
indexes :author_id, type: :integer
# The field assignee_id does not exist in issues table anymore.
# Nevertheless we'll keep this field as is because we don't want users to rebuild index
# + the ES treats arrays transparently so
# to any integer field you can write any array of integers and you don't have to change mapping.
# More over you can query those items just like a single integer value.
indexes :assignee_id, type: :integer
indexes :confidential, type: :boolean
end
......@@ -26,10 +33,12 @@ module Elastic
# We don't use as_json(only: ...) because it calls all virtual and serialized attributtes
# https://gitlab.com/gitlab-org/gitlab-ee/issues/349
[:id, :iid, :title, :description, :created_at, :updated_at, :state, :project_id, :author_id, :assignee_id, :confidential].each do |attr|
[:id, :iid, :title, :description, :created_at, :updated_at, :state, :project_id, :author_id, :confidential].each do |attr|
data[attr.to_s] = safely_read_attribute_for_elasticsearch(attr)
end
data['assignee_id'] = safely_read_attribute_for_elasticsearch(:assignee_ids)
data
end
......
......@@ -34,7 +34,7 @@ module Elastic
if noteable.is_a?(Issue)
data['issue'] = {
assignee_id: noteable.assignee_id,
assignee_id: noteable.assignee_ids,
author_id: noteable.author_id,
confidential: noteable.confidential
}
......
class IssueAssignee < ActiveRecord::Base
extend Gitlab::CurrentSettings
belongs_to :issue
belongs_to :assignee, class_name: "User", foreign_key: :user_id
after_create :update_assignee_cache_counts
after_destroy :update_assignee_cache_counts
# EE-specific
after_create :update_elasticsearch_index
after_destroy :update_elasticsearch_index
# EE-specific
def update_assignee_cache_counts
assignee&.update_cache_counts
end
def update_elasticsearch_index
if current_application_settings.elasticsearch_indexing?
ElasticIndexerWorker.perform_async(
:update,
'Issue',
issue.id,
changed_fields: ['assignee_ids']
)
end
end
end
......@@ -5,7 +5,7 @@ class ElasticIndexerWorker
sidekiq_options queue: :elasticsearch, retry: 2
ISSUE_TRACKED_FIELDS = %w(assignee_id author_id confidential).freeze
ISSUE_TRACKED_FIELDS = %w(assignee_ids author_id confidential).freeze
def perform(operation, class_name, record_id, options = {})
return true unless current_application_settings.elasticsearch_indexing?
......
......@@ -35,7 +35,9 @@ describe Issue, elastic: true do
expected_hash = issue.attributes.extract!('id', 'iid', 'title', 'description', 'created_at',
'updated_at', 'state', 'project_id', 'author_id',
'assignee_id', 'confidential')
'confidential')
expected_hash['assignee_id'] = []
expect(issue.as_indexed_json).to eq(expected_hash)
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