mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 09:26:54 -06:00
FEATURE: Enable pagination of /posts.json
This commit is contained in:
parent
1d24d8471e
commit
9e9119d1c1
@ -26,8 +26,14 @@ class PostsController < ApplicationController
|
||||
end
|
||||
|
||||
def latest
|
||||
params.permit(:before)
|
||||
last_post_id = params[:before].to_i
|
||||
last_post_id = Post.last.id if last_post_id <= 0
|
||||
|
||||
# last 50 post IDs only, to avoid counting deleted posts in security check
|
||||
posts = Post.order(created_at: :desc)
|
||||
.where('posts.id > ?', Post.last.id - 50) # last 50 post IDs only, to avoid counting deleted posts in security check
|
||||
.where('posts.id <= ?', last_post_id)
|
||||
.where('posts.id > ?', last_post_id - 50)
|
||||
.includes(topic: :category)
|
||||
.includes(:user)
|
||||
.limit(50)
|
||||
|
Loading…
Reference in New Issue
Block a user