mirror of
https://github.com/discourse/discourse.git
synced 2025-05-31 20:45:35 +08:00
FEATURE: Add lazy loading to user bookmarks list (#9317)
This is so users with huge amount of bookmarks do not have to wait a long time to see results. * Add a bookmark list and list serializer to server-side to be able to handle paging and load more URL * Use load-more component to load more bookmark items, 20 at a time in user activity * Change the way current user is loaded for bookmark ember models because it was breaking/losing resolvedTimezone when loading more items
This commit is contained in:
@ -22,6 +22,8 @@ class BookmarkQuery
|
||||
@user = user
|
||||
@params = params
|
||||
@guardian = guardian || Guardian.new(@user)
|
||||
@page = @params[:page].to_i
|
||||
@limit = @params[:limit].present? ? @params[:limit].to_i : @params[:per_page]
|
||||
end
|
||||
|
||||
def list_all
|
||||
@ -34,10 +36,12 @@ class BookmarkQuery
|
||||
|
||||
results = results.merge(Post.secured(@guardian))
|
||||
|
||||
if @params[:limit]
|
||||
results = results.limit(@params[:limit])
|
||||
if @page.positive?
|
||||
results = results.offset(@page * @params[:per_page])
|
||||
end
|
||||
|
||||
results = results.limit(@limit)
|
||||
|
||||
if BookmarkQuery.preloaded_custom_fields.any?
|
||||
Topic.preload_custom_fields(
|
||||
results.map(&:topic), BookmarkQuery.preloaded_custom_fields
|
||||
|
Reference in New Issue
Block a user