See context on Linear. The new query behaves differently from the old query for messages that have multiple associated uploads. We want to return 20 distinct messages, not 20 rows.
There might be a way to keep the window function construction, but I don't have time right now to investigate. The old query is definitely messier than the new one, but the performance is approximately the same after D4674 and D4673.