Commit e09eabb2 authored by Dmytro Zaporozhets (DZ)'s avatar Dmytro Zaporozhets (DZ)

Merge branch '321634-drop-at-most' into 'master'

Remove at_most helper on ApplicationRecord

See merge request gitlab-org/gitlab!54555
parents 80ed7104 95b1b3ea
...@@ -27,7 +27,7 @@ module AlertManagement ...@@ -27,7 +27,7 @@ module AlertManagement
first_id = project.alert_management_http_integrations first_id = project.alert_management_http_integrations
.ordered_by_id .ordered_by_id
.select(:id) .select(:id)
.at_most(1) .limit(1)
@collection = collection.id_in(first_id) @collection = collection.id_in(first_id)
end end
......
...@@ -42,10 +42,6 @@ class ApplicationRecord < ActiveRecord::Base ...@@ -42,10 +42,6 @@ class ApplicationRecord < ActiveRecord::Base
false false
end end
def self.at_most(count)
limit(count)
end
def self.safe_find_or_create_by!(*args, &block) def self.safe_find_or_create_by!(*args, &block)
safe_find_or_create_by(*args, &block).tap do |record| safe_find_or_create_by(*args, &block).tap do |record|
raise ActiveRecord::RecordNotFound unless record.present? raise ActiveRecord::RecordNotFound unless record.present?
......
...@@ -17,7 +17,7 @@ module MergeRequests ...@@ -17,7 +17,7 @@ module MergeRequests
.opened .opened
.by_target_branch(merge_request.source_branch) .by_target_branch(merge_request.source_branch)
.preload_source_project .preload_source_project
.at_most(MAX_RETARGET_MERGE_REQUESTS) .limit(MAX_RETARGET_MERGE_REQUESTS)
other_merge_requests.find_each do |other_merge_request| other_merge_requests.find_each do |other_merge_request|
# Update only MRs on projects that we have access to # Update only MRs on projects that we have access to
......
...@@ -48,7 +48,7 @@ module NetworkPolicies ...@@ -48,7 +48,7 @@ module NetworkPolicies
if environment_id if environment_id
Clusters::KubernetesNamespace.where(environment: project.environments.id_in(environment_id)) Clusters::KubernetesNamespace.where(environment: project.environments.id_in(environment_id))
else else
Clusters::KubernetesNamespace.where(environment: project.environments.available.at_most(LIMIT)) Clusters::KubernetesNamespace.where(environment: project.environments.available.limit(LIMIT))
end end
kubernetes_namespaces kubernetes_namespaces
......
...@@ -38,7 +38,7 @@ module Gitlab ...@@ -38,7 +38,7 @@ module Gitlab
def fetch_page(relation) def fetch_page(relation)
relation = relation.by_updated_at relation = relation.by_updated_at
notes = relation.at_most(LIMIT + 1).to_a notes = relation.limit(LIMIT + 1).to_a
return [notes, false] unless notes.size > LIMIT return [notes, false] unless notes.size > LIMIT
......
...@@ -93,13 +93,6 @@ RSpec.describe ApplicationRecord do ...@@ -93,13 +93,6 @@ RSpec.describe ApplicationRecord do
end end
end end
describe '.at_most' do
it 'limits the number of records returned' do
create_list(:user, 3)
expect(User.at_most(2).count).to eq(2)
end
end
describe '.where_exists' do describe '.where_exists' do
it 'produces a WHERE EXISTS query' do it 'produces a WHERE EXISTS query' do
user = create(:user) user = create(:user)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment