Performance regression: we are using ORDER BY on finder methods again
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/12633 makes finder methods on Sortable
do the right thing:
[1] pry(main)> Issue.find_by(project_id: 1, iid: 1); nil
Issue Load (0.8ms) SELECT "issues".* FROM "issues" WHERE "issues"."deleted_at" IS NULL AND "issues"."project_id" = $1 AND "issues"."iid" = $2 LIMIT 1 [["project_id", 1], ["iid", 1]]
=> nil
But it doesn't work on collection proxies:
[2] pry(main)> Project.find(1).issues.find_by(iid: 1); nil
Project Load (1.1ms) SELECT "projects".* FROM "projects" WHERE "projects"."id" = $1 LIMIT 1 [["id", 1]]
Issue Load (0.4ms) SELECT "issues".* FROM "issues" WHERE "issues"."deleted_at" IS NULL AND "issues"."project_id" = $1 AND "issues"."iid" = $2 ORDER BY "issues"."id" DESC LIMIT 1 [["project_id", 1], ["iid", 1]]
This causes things like https://gitlab.com/gitlab-org/gitlab-ce/issues/27164#note_35013814, which we thought we'd rid ourselves of.