Fixes #3095 - Not all attributes if chats are indexed by elasticsearch (chat.name and tags are missing)

This commit is contained in:
Martin Edenhofer 2020-07-10 15:30:44 +02:00 committed by Thorsten Eckel
parent 5d9ecee99c
commit 71dcde5876
5 changed files with 48 additions and 21 deletions

View file

@ -8,6 +8,8 @@ class Chat::Session < ApplicationModel
# rubocop:disable Rails/InverseOf # rubocop:disable Rails/InverseOf
has_many :messages, class_name: 'Chat::Message', foreign_key: 'chat_session_id' has_many :messages, class_name: 'Chat::Message', foreign_key: 'chat_session_id'
belongs_to :user, class_name: 'User', optional: true
belongs_to :chat, class_name: 'Chat'
# rubocop:enable Rails/InverseOf # rubocop:enable Rails/InverseOf
before_create :generate_session_id before_create :generate_session_id

View file

@ -2,9 +2,6 @@
module Chat::Session::SearchIndex module Chat::Session::SearchIndex
extend ActiveSupport::Concern extend ActiveSupport::Concern
# methods defined here are going to extend the class, not the instance of it
class_methods do
=begin =begin
lookup name of ref. objects lookup name of ref. objects
@ -22,7 +19,7 @@ returns
attributes = super attributes = super
return if !attributes return if !attributes
attributes[:tags] = tag_list attributes['tags'] = tag_list
messages = Chat::Message.where(chat_session_id: id) messages = Chat::Message.where(chat_session_id: id)
attributes['messages'] = [] attributes['messages'] = []
@ -36,6 +33,5 @@ returns
attributes attributes
end end
end
end end

View file

@ -0,0 +1,5 @@
FactoryBot.define do
factory :'chat/session' do
chat_id { Chat.pluck(:id).sample }
end
end

View file

@ -0,0 +1,24 @@
require 'rails_helper'
RSpec.describe Chat::Session, type: :model do
describe '.search_index_attribute_lookup' do
subject(:chat_session) { create(:'chat/session', user: chat_user, chat: chat) }
let(:chat) { create(:chat) }
let(:chat_user) { create(:agent) }
it 'verify message attribute' do
expect(chat_session.search_index_attribute_lookup['messages']).to eq []
end
it 'verify user attribute' do
expect(chat_session.search_index_attribute_lookup['user']['id']).to eq chat_user.id
end
it 'verify chat attribute' do
expect(chat_session.search_index_attribute_lookup['chat']).to eq chat.name
end
end
end

View file

@ -595,7 +595,7 @@ RSpec.describe 'Monitoring', type: :request do
expect(json_response['message']).to be_truthy expect(json_response['message']).to be_truthy
expect(json_response['issues']).to be_truthy expect(json_response['issues']).to be_truthy
expect(json_response['healthy']).to eq(false) expect(json_response['healthy']).to eq(false)
expect( json_response['message']).to eq("Failed to run background job #1 'SearchIndexJob' 1 time(s) with 1 attempt(s).") expect( json_response['message']).to eq("Failed to run background job #1 'SearchIndexAssociationsJob' 1 time(s) with 1 attempt(s).;Failed to run background job #2 'SearchIndexJob' 1 time(s) with 1 attempt(s).")
# add another job # add another job
manual_added = SearchIndexJob.perform_later('Ticket', 1) manual_added = SearchIndexJob.perform_later('Ticket', 1)
@ -609,7 +609,7 @@ RSpec.describe 'Monitoring', type: :request do
expect(json_response['message']).to be_truthy expect(json_response['message']).to be_truthy
expect(json_response['issues']).to be_truthy expect(json_response['issues']).to be_truthy
expect(json_response['healthy']).to eq(false) expect(json_response['healthy']).to eq(false)
expect( json_response['message']).to eq("Failed to run background job #1 'SearchIndexJob' 2 time(s) with 11 attempt(s).") expect( json_response['message']).to eq("Failed to run background job #1 'SearchIndexAssociationsJob' 1 time(s) with 1 attempt(s).;Failed to run background job #2 'SearchIndexJob' 2 time(s) with 11 attempt(s).")
# add another job # add another job
dummy_class = Class.new(ApplicationJob) do dummy_class = Class.new(ApplicationJob) do
@ -630,7 +630,7 @@ RSpec.describe 'Monitoring', type: :request do
expect(json_response['message']).to be_truthy expect(json_response['message']).to be_truthy
expect(json_response['issues']).to be_truthy expect(json_response['issues']).to be_truthy
expect(json_response['healthy']).to eq(false) expect(json_response['healthy']).to eq(false)
expect( json_response['message']).to eq("Failed to run background job #1 'Object' 1 time(s) with 5 attempt(s).;Failed to run background job #2 'SearchIndexJob' 2 time(s) with 11 attempt(s).") expect(json_response['message']).to eq("Failed to run background job #1 'Object' 1 time(s) with 5 attempt(s).;Failed to run background job #2 'SearchIndexAssociationsJob' 1 time(s) with 1 attempt(s).;Failed to run background job #3 'SearchIndexJob' 2 time(s) with 11 attempt(s).")
# reset settings # reset settings
Setting.set('es_url', prev_es_config) Setting.set('es_url', prev_es_config)
@ -649,7 +649,7 @@ RSpec.describe 'Monitoring', type: :request do
expect(json_response['message']).to be_truthy expect(json_response['message']).to be_truthy
expect(json_response['issues']).to be_truthy expect(json_response['issues']).to be_truthy
expect(json_response['healthy']).to eq(false) expect(json_response['healthy']).to eq(false)
expect(json_response['message']).to eq("13 failing background jobs;Failed to run background job #1 'Object' 8 time(s) with 40 attempt(s).;Failed to run background job #2 'SearchIndexJob' 2 time(s) with 11 attempt(s).") expect(json_response['message']).to eq("14 failing background jobs;Failed to run background job #1 'Object' 7 time(s) with 35 attempt(s).;Failed to run background job #2 'SearchIndexAssociationsJob' 1 time(s) with 1 attempt(s).;Failed to run background job #3 'SearchIndexJob' 2 time(s) with 11 attempt(s).")
# cleanup # cleanup
Delayed::Job.delete_all Delayed::Job.delete_all