Update query simplification
What does this MR do?
make a query better to read. I did try this, but ran into some trouble. Not sure what changed, but this works now, for both Rails 5 and Rails 4.
What are the relevant issue numbers?
Closes: https://gitlab.com/gitlab-org/gitlab-ce/issues/49873