FIX: Update quotes after moving posts (PR #8326)


You’ve signed the CLA, udan11. Thank you! This pull request is ready for review.

This pull request has been mentioned on Discourse Meta. There might be relevant details there:

This is getting quite sophisticated!

Looks good and it should work with a large portion of quotes. :+1: I tested it on a larger database and it seems to be quite fast even though the explain plan doesn’t looks that good (probably because of the temp table):

Update on posts p  (cost=141.40..3859.55 rows=1142 width=788)
  ->  Nested Loop  (cost=141.40..3859.55 rows=1142 width=788)
        ->  Hash Join  (cost=141.11..191.63 rows=1142 width=32)
              Hash Cond: (mp.old_post_id = qp.quoted_post_id)
              ->  Seq Scan on moved_posts mp  (cost=0.00..19.70 rows=970 width=26)
              ->  Hash  (cost=82.16..82.16 rows=4716 width=14)
                    ->  Seq Scan on quoted_posts qp  (cost=0.00..82.16 rows=4716 width=14)
        ->  Index Scan using posts_pkey on posts p  (cost=0.29..3.17 rows=1 width=1164)
              Index Cond: (id = qp.post_id)