mirror of
https://github.com/discourse/discourse.git
synced 2024-11-24 01:58:12 +08:00
5092c9804c
It used to return the next URL anyway which lead to an additional request. On the frontend, if the result set was empty, it kept retrying until at least one result was returned. This bug is fixed in this commit too.
34 lines
822 B
Ruby
34 lines
822 B
Ruby
# frozen_string_literal: true
|
|
|
|
class UserBookmarkList
|
|
include ActiveModel::Serialization
|
|
|
|
PER_PAGE = 20
|
|
|
|
attr_reader :bookmarks, :per_page, :has_more
|
|
attr_accessor :more_bookmarks_url, :bookmark_serializer_opts
|
|
|
|
def initialize(user:, guardian:, params:)
|
|
@user = user
|
|
@guardian = guardian
|
|
@params = params
|
|
|
|
@params.merge!(per_page: PER_PAGE) if params[:per_page].blank?
|
|
@params[:per_page] = PER_PAGE if @params[:per_page] > PER_PAGE
|
|
|
|
@bookmarks = []
|
|
@bookmark_serializer_opts = {}
|
|
end
|
|
|
|
def load(&blk)
|
|
query = BookmarkQuery.new(user: @user, guardian: @guardian, params: @params)
|
|
@bookmarks = query.list_all(&blk)
|
|
@has_more = (@params[:page].to_i + 1) * @params[:per_page] < query.count
|
|
@bookmarks
|
|
end
|
|
|
|
def per_page
|
|
@per_page ||= @params[:per_page]
|
|
end
|
|
end
|