Follow-up from "Improve large MR count query: avoid primary sticking and add caching"

The following discussion from !57341 (merged) should be addressed:

  • @ayufan started a discussion:

    @aakriti.gupta

    I think this usage is wrong. We should not modify a global session that is outside of this getter as this confuses other calls and guarantees we have around stickiness to primary.

    If you truly want do use replicas, you should ensure that you run in a replicas context.

    I was thinking about something along this way: !57477 (diffs).

Reason

This was created after looking at ELK logs where we see some sidekiq jobs using replicas even though they are not configured to do so: https://log.gprd.gitlab.net/goto/189996cc467d77ae1005e4cba0c29b00

Edited by Kamil Trzciński