From 725d2411e5e7d48a78d2ac3df9d995ff9992a16a Mon Sep 17 00:00:00 2001 From: pgcd Date: Sun, 3 Nov 2024 23:00:03 +0100 Subject: [PATCH] This commit fixes an undesirable geometric query memory usage introduced in b908abe35a0121e7df69ab3bbced259b6a2b7104 (#29539) I have been unable to figure out a way of testing this usefully (as I fear it would require creating several thousands of objects), but existing tests pass and a manual test with ~400k topics succeeds after the fix, while it would hang indefinitely and/or consume all disk space before the fix. I have reported the initial problem and my findings in https://meta.discourse.org/t/topic-reset-all-highest-exhausts-all-available-disk-space/333837 --- app/models/topic.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/models/topic.rb b/app/models/topic.rb index d796b3c895f..f17c7eecf53 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -881,7 +881,8 @@ class Topic < ActiveRecord::Base WHERE topics.archetype <> 'private_message' AND X.topic_id = topics.id AND - Y.topic_id = topics.id AND ( + Y.topic_id = topics.id AND + Z.topic_id = topics.id AND ( topics.highest_staff_post_number <> X.highest_post_number OR topics.highest_post_number <> Y.highest_post_number OR topics.last_posted_at <> Y.last_posted_at OR @@ -926,7 +927,8 @@ class Topic < ActiveRecord::Base WHERE topics.archetype = 'private_message' AND X.topic_id = topics.id AND - Y.topic_id = topics.id AND ( + Y.topic_id = topics.id AND + Z.topic_id = topics.id AND ( topics.highest_staff_post_number <> X.highest_post_number OR topics.highest_post_number <> Y.highest_post_number OR topics.last_posted_at <> Y.last_posted_at OR