forked from chatwoot/chatwoot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Performance] Optimize queries in conversation/message finders (chatw…
…oot#364) * [Performance] Optimize queries in conversation/message finders * Add message_finder spec * Fix message_finder spec
- Loading branch information
1 parent
cfc5670
commit a7cb75e
Showing
5 changed files
with
59 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,3 +43,5 @@ public/packs* | |
# coverage report | ||
buildreports | ||
coverage | ||
|
||
/storage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
require 'rails_helper' | ||
|
||
describe ::MessageFinder do | ||
subject(:message_finder) { described_class.new(conversation, params) } | ||
|
||
let!(:account) { create(:account) } | ||
let!(:user) { create(:user, account: account) } | ||
let!(:inbox) { create(:inbox, account: account) } | ||
let!(:conversation) { create(:complete_conversation, account: account, inbox: inbox, assignee: user) } | ||
|
||
before do | ||
create(:message, account: account, inbox: inbox, conversation: conversation) | ||
create(:message, message_type: 'activity', account: account, inbox: inbox, conversation: conversation) | ||
create(:message, message_type: 'activity', account: account, inbox: inbox, conversation: conversation) | ||
create(:message, message_type: 'outgoing', account: account, inbox: inbox, conversation: conversation) | ||
end | ||
|
||
describe '#perform' do | ||
context 'with filter_internal_messages false' do | ||
let(:params) { { filter_internal_messages: false } } | ||
|
||
it 'filter conversations by status' do | ||
result = message_finder.perform | ||
expect(result.count).to be 4 | ||
end | ||
end | ||
|
||
context 'with filter_internal_messages true' do | ||
let(:params) { { filter_internal_messages: true } } | ||
|
||
it 'filter conversations by status' do | ||
result = message_finder.perform | ||
expect(result.count).to be 2 | ||
end | ||
end | ||
|
||
context 'with before attribute' do | ||
let!(:outgoing) { create(:message, message_type: 'outgoing', account: account, inbox: inbox, conversation: conversation) } | ||
let(:params) { { before: outgoing.id } } | ||
|
||
it 'filter conversations by status' do | ||
result = message_finder.perform | ||
expect(result.count).to be 4 | ||
end | ||
end | ||
end | ||
end |