Followed users events (filter ALL) should be ordered by id DESC
What does this MR do and why?
!77028 (merged) was created to improve the performance of finding followed users events and partially resolve #346435 (closed). Unfortunately the changes in the MR had a bug where queried events didn't have an explicit sort order. This MR fixes the sort order to be id
DESC.
How to set up and validate locally
Visit "Activity" and click "Followed users" tab then filter for "ALL" events.
before | after |
---|---|
![]() |
![]() |
Migration output
UP:
== 20211230112517 RemoveIndexEventsOnAuthorIdAndActionAndId: migrating ========
-- transaction_open?()
-> 0.0000s
-- indexes(:events)
-> 0.0092s
-- execute("SET statement_timeout TO 0")
-> 0.0006s
-- remove_index(:events, {:algorithm=>:concurrently, :name=>"index_events_on_author_id_and_action_and_id"})
-> 0.0101s
-- execute("RESET statement_timeout")
-> 0.0006s
== 20211230112517 RemoveIndexEventsOnAuthorIdAndActionAndId: migrated (0.0240s)
== 20211230113031 AddIndexToEventsOnAuthorIdAndActionAndIdDesc: migrating =====
-- transaction_open?()
-> 0.0000s
-- index_exists?(:events, [:author_id, :action, :id], {:order=>{:id=>:desc}, :name=>"index_events_on_author_id_and_action_and_id_desc", :algorithm=>:concurrently})
-> 0.0061s
-- execute("SET statement_timeout TO 0")
-> 0.0005s
-- add_index(:events, [:author_id, :action, :id], {:order=>{:id=>:desc}, :name=>"index_events_on_author_id_and_action_and_id_desc", :algorithm=>:concurrently})
-> 0.0102s
-- execute("RESET statement_timeout")
-> 0.0004s
== 20211230113031 AddIndexToEventsOnAuthorIdAndActionAndIdDesc: migrated (0.0190s)
DOWN:
== 20211230113031 AddIndexToEventsOnAuthorIdAndActionAndIdDesc: reverting =====
-- transaction_open?()
-> 0.0000s
-- indexes(:events)
-> 0.0059s
-- execute("SET statement_timeout TO 0")
-> 0.0006s
-- remove_index(:events, {:algorithm=>:concurrently, :name=>"index_events_on_author_id_and_action_and_id_desc"})
-> 0.0029s
-- execute("RESET statement_timeout")
-> 0.0006s
== 20211230113031 AddIndexToEventsOnAuthorIdAndActionAndIdDesc: reverted (0.0118s)
== 20211230112517 RemoveIndexEventsOnAuthorIdAndActionAndId: reverting ========
== 20211230112517 RemoveIndexEventsOnAuthorIdAndActionAndId: reverted (0.0000s)
Query plans
There really isn't a change in the query plans.
Before: https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/7814/commands/27864
After: https://explain-depesz.postgres.ai/s/Ta
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Edited by euko