mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 09:42:07 +08:00
33 lines
718 B
Ruby
33 lines
718 B
Ruby
# frozen_string_literal: true
|
|
|
|
##
|
|
# Allows us to query Bookmark records for lists. Used mainly
|
|
# in the user/activity/bookmarks page.
|
|
|
|
class BookmarkQuery
|
|
def initialize(user, params = {})
|
|
@user = user
|
|
@params = params
|
|
end
|
|
|
|
def list_all
|
|
results = user_bookmarks
|
|
.joins('INNER JOIN topics ON topics.id = bookmarks.topic_id')
|
|
.joins('INNER JOIN posts ON posts.id = bookmarks.post_id')
|
|
.joins('INNER JOIN users ON users.id = posts.user_id')
|
|
.order('created_at DESC')
|
|
|
|
if @params[:limit]
|
|
results = results.limit(@params[:limit])
|
|
end
|
|
|
|
results
|
|
end
|
|
|
|
private
|
|
|
|
def user_bookmarks
|
|
Bookmark.where(user: @user).includes(:topic).includes(post: :user)
|
|
end
|
|
end
|