Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PERF: defer loading channels (#26155)
Prior to this change we would pre-load all the user channels which making initial page load slower. This change will make them be loaded right after initial load. In the past this was not possible as the channels would have to be loaded on each page transition. However since about a year, we made the channels to be cached on the frontend and no other request will be needed. I have decided for now to not show a loading state in the sidebar as I think it would be noise, but we can reconsider this later. Note given we don't have the channels loaded at first certain things where harder to accomplish. The biggest UX change of this commit is that we removed all the complex logic of computing the best channel to display when you load /chat. We will now store the id of the last channel you visited and will use this id to decide which channel to show.
- Loading branch information
Showing
28 changed files
with
391 additions
and
877 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
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,43 @@ | ||
# frozen_string_literal: true | ||
|
||
module Chat | ||
# List of the channels a user is tracking | ||
# | ||
# @example | ||
# Chat::ListUserChannels.call(guardian: guardian, **optional_params) | ||
# | ||
class ListUserChannels | ||
include Service::Base | ||
|
||
# @!method call(guardian:) | ||
# @param [Guardian] guardian | ||
# @return [Service::Base::Context] | ||
|
||
model :structured | ||
step :inject_unread_thread_overview | ||
model :post_allowed_category_ids, optional: true | ||
|
||
private | ||
|
||
def fetch_structured(guardian:) | ||
::Chat::ChannelFetcher.structured(guardian) | ||
end | ||
|
||
def inject_unread_thread_overview(structured:, guardian:) | ||
structured[:unread_thread_overview] = ::Chat::TrackingStateReportQuery.call( | ||
guardian: guardian, | ||
channel_ids: structured[:public_channels].map(&:id), | ||
include_threads: true, | ||
include_read: false, | ||
include_last_reply_details: true, | ||
).thread_unread_overview_by_channel | ||
end | ||
|
||
def fetch_post_allowed_category_ids(guardian:, structured:) | ||
::Category | ||
.post_create_allowed(guardian) | ||
.where(id: structured[:public_channels].map { |c| c.chatable_id }) | ||
.pluck(:id) | ||
end | ||
end | ||
end |
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
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
Oops, something went wrong.
bbb8595
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This commit has been mentioned on Discourse Meta. There might be relevant details there:
https://meta.discourse.org/t/logs-job-exception-unexpected-return-error/299963/1