mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
FIX: Do not raise error if most liked user is deleted
This commit is contained in:
@ -192,10 +192,12 @@ protected
|
|||||||
|
|
||||||
lookup = AvatarLookup.new(user_ids)
|
lookup = AvatarLookup.new(user_ids)
|
||||||
user_ids.map do |user_id|
|
user_ids.map do |user_id|
|
||||||
|
lookup_hash = lookup[user_id]
|
||||||
|
|
||||||
UserWithCount.new(
|
UserWithCount.new(
|
||||||
lookup[user_id].attributes.merge(count: user_hash[user_id])
|
lookup_hash.attributes.merge(count: user_hash[user_id])
|
||||||
)
|
) if lookup_hash.present?
|
||||||
end.sort_by { |u| -u[:count] }
|
end.compact.sort_by { |u| -u[:count] }
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -38,4 +38,22 @@ describe UserSummary do
|
|||||||
expect(summary.top_categories.length).to eq(0)
|
expect(summary.top_categories.length).to eq(0)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "is robust enough to handle bad data" do
|
||||||
|
UserActionCreator.enable
|
||||||
|
|
||||||
|
liked_post = create_post
|
||||||
|
user = Fabricate(:user)
|
||||||
|
PostAction.act(user, liked_post, PostActionType.types[:like])
|
||||||
|
|
||||||
|
users = UserSummary.new(user, Guardian.new).most_liked_users
|
||||||
|
|
||||||
|
expect(users.map(&:id)).to eq([liked_post.user_id])
|
||||||
|
|
||||||
|
# really we should not be corrupting stuff like this
|
||||||
|
# but in production dbs this can happens sometimes I guess
|
||||||
|
liked_post.user.delete
|
||||||
|
|
||||||
|
users = UserSummary.new(user, Guardian.new).most_liked_users
|
||||||
|
expect(users).to eq([])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user