Skip to content

Commit 027860f

Browse files
authored
Change deprecated mongodb repairDatabase command to compact (errbit#1502)
1 parent a0592ab commit 027860f

File tree

4 files changed

+22
-16
lines changed

4 files changed

+22
-16
lines changed

app/interactors/outdated_problem_clearer.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def execute
1010
criteria.each do |problem|
1111
ProblemDestroy.new(problem).execute
1212
end
13-
repair_database
13+
compact_database
1414
end
1515
end
1616
end
@@ -25,7 +25,10 @@ def criteria
2525
@criteria ||= Problem.where(:last_notice_at.lt => Errbit::Config.notice_deprecation_days.to_f.days.ago)
2626
end
2727

28-
def repair_database
29-
Mongoid.default_client.command repairDatabase: 1
28+
def compact_database
29+
collections = Mongoid.default_client.collections
30+
collections.map(&:name).map do |collection|
31+
Mongoid.default_client.command compact: collection
32+
end
3033
end
3134
end

app/interactors/resolved_problem_clearer.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def execute
1010
criteria.each do |problem|
1111
ProblemDestroy.new(problem).execute
1212
end
13-
repair_database
13+
compact_database
1414
end
1515
end
1616
end
@@ -25,7 +25,10 @@ def criteria
2525
@criteria = Problem.resolved
2626
end
2727

28-
def repair_database
29-
Mongoid.default_client.command repairDatabase: 1
28+
def compact_database
29+
collections = Mongoid.default_client.collections
30+
collections.map(&:name).map do |collection|
31+
Mongoid.default_client.command compact: collection
32+
end
3033
end
3134
end

spec/interactors/outdated_problem_clearer_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@
2222
Problem.count
2323
}
2424
end
25-
it 'not repair database' do
25+
it 'not compact database' do
2626
allow(Mongoid.default_client).to receive(:command).and_call_original
27-
expect(Mongoid.default_client).to_not receive(:command).with(repairDatabase: 1)
27+
expect(Mongoid.default_client).to_not receive(:command).with(compact: an_instance_of(String))
2828
outdated_problem_clearer.execute
2929
end
3030
end
3131

3232
context "with old problems" do
3333
before do
3434
allow(Mongoid.default_client).to receive(:command).and_call_original
35-
allow(Mongoid.default_client).to receive(:command).with(repairDatabase: 1)
35+
allow(Mongoid.default_client).to receive(:command).with(compact: an_instance_of(String)).at_least(1)
3636
problems.first.update(last_notice_at: Time.zone.at(946_684_800.0))
3737
problems.second.update(last_notice_at: Time.zone.at(946_684_800.0))
3838
end
@@ -47,8 +47,8 @@
4747
expect(Problem.where(_id: problems.second.id).first).to be_nil
4848
end
4949

50-
it 'repair database' do
51-
expect(Mongoid.default_client).to receive(:command).with(repairDatabase: 1)
50+
it 'compact database' do
51+
expect(Mongoid.default_client).to receive(:command).with(compact: an_instance_of(String)).at_least(1)
5252
outdated_problem_clearer.execute
5353
end
5454
end

spec/interactors/resolved_problem_clearer_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@
1818
Problem.count
1919
}
2020
end
21-
it 'not repair database' do
21+
it 'not compact database' do
2222
allow(Mongoid.default_client).to receive(:command).and_call_original
23-
expect(Mongoid.default_client).to_not receive(:command).with(repairDatabase: 1)
23+
expect(Mongoid.default_client).to_not receive(:command).with(compact: an_instance_of(String))
2424
resolved_problem_clearer.execute
2525
end
2626
end
2727

2828
context "with problem resolve" do
2929
before do
3030
allow(Mongoid.default_client).to receive(:command).and_call_original
31-
allow(Mongoid.default_client).to receive(:command).with(repairDatabase: 1)
31+
allow(Mongoid.default_client).to receive(:command).with(compact: an_instance_of(String)).at_least(1)
3232
problems.first.resolve!
3333
problems.second.resolve!
3434
end
@@ -43,8 +43,8 @@
4343
expect(Problem.where(_id: problems.second.id).first).to be_nil
4444
end
4545

46-
it 'repair database' do
47-
expect(Mongoid.default_client).to receive(:command).with(repairDatabase: 1)
46+
it 'compact database' do
47+
expect(Mongoid.default_client).to receive(:command).with(compact: an_instance_of(String)).at_least(1)
4848
resolved_problem_clearer.execute
4949
end
5050
end

0 commit comments

Comments
 (0)