mirror of
https://github.com/discourse/discourse.git
synced 2025-06-04 05:41:39 +08:00
FIX: Posts can belong to hard-deleted topics (#17329)
* FIX: Posts can belong to hard-deleted topics This was a problem when serializing deleted posts because they might belong to a topic that was permanently deleted. This caused to DB lookup to fail immediately and raise an exception. In this case, the endpoint returned a 404. * FIX: Remove N+1 queries Deleted topics were not loaded because of the default scope that filters out all deleted topics. It executed a query for each deleted topic.
This commit is contained in:
@ -705,10 +705,13 @@ class PostsController < ApplicationController
|
||||
private
|
||||
|
||||
def user_posts(guardian, user_id, opts)
|
||||
posts = Post.includes(:user, :topic, :deleted_by, :user_actions)
|
||||
.where(user_id: user_id)
|
||||
.with_deleted
|
||||
.order(created_at: :desc)
|
||||
# Topic.unscoped is necessary to remove the default deleted_at: nil scope
|
||||
posts = Topic.unscoped do
|
||||
Post.includes(:user, :topic, :deleted_by, :user_actions)
|
||||
.where(user_id: user_id)
|
||||
.with_deleted
|
||||
.order(created_at: :desc)
|
||||
end
|
||||
|
||||
if guardian.user.moderator?
|
||||
|
||||
|
Reference in New Issue
Block a user