-
- Downloads
Added FromUnion to easily select from a UNION
This commit adds the module `FromUnion`, which provides the class method `from_union`. This simplifies the process of selecting data from the result of a UNION, and reduces the likelihood of making mistakes. As a result, instead of this: union = Gitlab::SQL::Union.new([foo, bar]) Foo.from("(#{union.to_sql}) #{Foo.table_name}") We can now write this instead: Foo.from_union([foo, bar]) This commit also includes some changes to make this new setup work properly. For example, a bug in Rails 4 (https://github.com/rails/rails/issues/24193) would break the use of `from("sub-query-here").includes(:relation)` in certain cases. There was also a CI query which appeared to repeat a lot of conditions from an outer query on an inner query, which isn't necessary. Finally, we include a RuboCop cop to ensure developers use this new module, instead of using Gitlab::SQL::Union directly. Fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/51307
parent
78b3eea7
No related branches found
No related tags found
Showing
- app/finders/members_finder.rb 1 addition, 1 deletionapp/finders/members_finder.rb
- app/finders/snippets_finder.rb 1 addition, 3 deletionsapp/finders/snippets_finder.rb
- app/finders/todos_finder.rb 5 additions, 8 deletionsapp/finders/todos_finder.rb
- app/finders/union_finder.rb 5 additions, 5 deletionsapp/finders/union_finder.rb
- app/models/badge.rb 2 additions, 0 deletionsapp/models/badge.rb
- app/models/ci/runner.rb 13 additions, 4 deletionsapp/models/ci/runner.rb
- app/models/concerns/from_union.rb 51 additions, 0 deletionsapp/models/concerns/from_union.rb
- app/models/event.rb 1 addition, 0 deletionsapp/models/event.rb
- app/models/group.rb 1 addition, 3 deletionsapp/models/group.rb
- app/models/label.rb 1 addition, 0 deletionsapp/models/label.rb
- app/models/merge_request.rb 6 additions, 9 deletionsapp/models/merge_request.rb
- app/models/namespace.rb 1 addition, 0 deletionsapp/models/namespace.rb
- app/models/note.rb 1 addition, 0 deletionsapp/models/note.rb
- app/models/project.rb 6 additions, 8 deletionsapp/models/project.rb
- app/models/project_authorization.rb 5 additions, 3 deletionsapp/models/project_authorization.rb
- app/models/snippet.rb 1 addition, 0 deletionsapp/models/snippet.rb
- app/models/todo.rb 1 addition, 0 deletionsapp/models/todo.rb
- app/models/user.rb 23 additions, 26 deletionsapp/models/user.rb
- app/services/labels/transfer_service.rb 7 additions, 7 deletionsapp/services/labels/transfer_service.rb
- lib/gitlab/contributions_calendar.rb 3 additions, 2 deletionslib/gitlab/contributions_calendar.rb
app/models/concerns/from_union.rb
0 → 100644
Please register or sign in to comment