mirror of
https://github.com/discourse/discourse.git
synced 2025-02-07 02:14:33 +08:00
![Bianca Nenciu](/assets/img/avatar_default.png)
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
|