mirror of
https://github.com/discourse/discourse.git
synced 2025-06-02 04:08:41 +08:00
FIX: Page size edge case for null last_read_message_id (#21811)
Followup 55ef2d0698627348e4f340f079504419c0939677. In the cases where the user has no last_read_message_id for a channel, we want to make sure that a page_size is set for the ChannelViewBuilder + MessagesQuery, otherwise we end up loading way more messages than needed (the additional message loading was fixed in the last commit).
This commit is contained in:
@ -93,6 +93,12 @@ RSpec.describe Chat::ChannelViewBuilder do
|
||||
it { is_expected.to fail_a_contract }
|
||||
end
|
||||
|
||||
context "when page_size is too big" do
|
||||
let(:page_size) { Chat::MessagesQuery::MAX_PAGE_SIZE + 1 }
|
||||
|
||||
it { is_expected.to fail_a_contract }
|
||||
end
|
||||
|
||||
context "when channel has threading_enabled and enable_experimental_chat_threaded_discussions is true" do
|
||||
before do
|
||||
channel.update!(threading_enabled: true)
|
||||
@ -247,6 +253,19 @@ RSpec.describe Chat::ChannelViewBuilder do
|
||||
it "does not error and still returns messages" do
|
||||
expect(subject.view.chat_messages).to eq([past_message_2, past_message_1, message])
|
||||
end
|
||||
|
||||
context "if page_size is nil" do
|
||||
let(:page_size) { nil }
|
||||
|
||||
it "calls the messages query with the default page size" do
|
||||
::Chat::MessagesQuery
|
||||
.expects(:call)
|
||||
.with(has_entries(page_size: Chat::MessagesQuery::MAX_PAGE_SIZE))
|
||||
.once
|
||||
.returns({ messages: [] })
|
||||
subject
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user