Commit Graph

4 Commits

Author SHA1 Message Date
Toon Claes d5080eb5ff Revert "Workaround for Rails 5, where LIMIT..."
This reverts commit 6823e7defb.

Originally implemented in
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/21839, but an
error was reported in
https://gitlab.com/gitlab-org/gitlab-ce/issues/51729 resulting in a
workaround introduced in
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/21879.

Now Rails 5.2 is used, this workaround no longer seems needed, so this
reverts it.
2019-07-16 14:09:11 +02:00
Jasper Maes 56296f1eda Remove rails4 specific code 2018-12-16 10:48:41 +01:00
Toon Claes 6823e7defb Work around a bug in Rails 5, where LIMIT causes trouble
The original code caused Rails to generate invalid SQL. The problem
lays in the `.arel` method in `ActiveRecord::Relation`. When there was
a `limit` on the relation, the `LIMIT` statement was taken over to
Arel, but the value wasn't.

```ruby
relation = Event.limit(2)
relation.to_sql
#=> "SELECT  `events`.* FROM `events` LIMIT 2"
relation.arel.to_sql
#=> "SELECT  `events`.* FROM `events` LIMIT ?"
```

Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/51729
2018-09-25 11:49:57 +02:00
Toon Claes ce830d3c60 Add Gitlab::Database::Subquery.self_join to delete_all with limit
`delete_all` doesn't support limit, so you'd need to subquery
that. And instead of subquerying with `where(id: query)`, it's better
to use an `INNER JOIN`. This method also works with MySQL, while
subquerying doesn't (without another layer of subquerying)

Reference:
https://stackoverflow.com/questions/17892762/mysql-this-version-of-mysql-doesnt-yet-support-limit-in-all-any-some-subqu/17892886#17892886
2018-09-20 16:27:09 +02:00