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:
Martin Brennan
2020-04-01 14:09:07 +10:00
committed by GitHub
parent b8d2261db9
commit c07dd0d22a
10 changed files with 155 additions and 61 deletions

View File

@ -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