PostMover performance improvements (PR #13687)

(Commits to be rebased-and-merged)

PERF: Improve post_timing performance when moving posts

Scanning for all possible invalid post_timing records in the destination topics can be a very expensive operation. The main aim is to avoid the data clashing with soon-to-be-moved posts, so we can reduce the scope of the query by targeting only rows which would actually cause a clash. post_timings has an index on (topic_id, post_number), so this is very fast.

On an example site, this reduced the query from ~6s to <10ms


PERF: Improve topic_user.liked update performance when moving posts

Previously we would re-calculate topic_user.liked for all users who have ever viewed the source or destination topic. This can be very expensive on large sites. Instead, we can use the array of moved post ids to find which users are actually affected by the move, and restrict the update query to only check/update their records.

On an example site this reduced the update_post_action_cache time from ~27s to 300ms

GitHub

On an example site, this reduced the query from ~6s to <10ms […] On an example site this reduced the update_post_action_cache time from ~27s to 300ms

:clap:

Fantastic improvements! :heart_eyes: