Skip to content

Commit 2e55d56

Browse files
authored
Remove unnecessary update! call in PendingChangesConcern (#3607)
Since records using this mixin will be bulk imported later in the process, using `update!` would trigger an immediate database write, validation checks, and callbacks for each record, negatively impacting performance without providing any benefit.
2 parents 22610f2 + 02269d7 commit 2e55d56

File tree

3 files changed

+1
-13
lines changed

3 files changed

+1
-13
lines changed

app/models/concerns/pending_changes_concern.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def stage_changes(attributes)
1313
end
1414

1515
if new_pending_changes.any?
16-
update!(pending_changes: pending_changes.merge(new_pending_changes))
16+
self.pending_changes = pending_changes.merge(new_pending_changes)
1717
end
1818
end
1919

spec/models/concerns/pending_changes_concern_spec.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@
3434
expect(model.pending_changes).to eq({ "family_name" => "Smith" })
3535
end
3636

37-
it "updates the pending_changes attribute" do
38-
expect { model.stage_changes(given_name: "Jane") }.to change {
39-
model.reload.pending_changes
40-
}.from({}).to({ "given_name" => "Jane" })
41-
end
42-
4337
it "does not update other attributes directly" do
4438
model.stage_changes(given_name: "Jane", family_name: "Smith")
4539

spec/models/patient_spec.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -509,12 +509,6 @@
509509
expect(patient.pending_changes).to eq({ "family_name" => "Smith" })
510510
end
511511

512-
it "updates the pending_changes attribute" do
513-
expect { patient.stage_changes(given_name: "Jane") }.to change {
514-
patient.reload.pending_changes
515-
}.from({}).to({ "given_name" => "Jane" })
516-
end
517-
518512
it "does not update other attributes directly" do
519513
patient.stage_changes(given_name: "Jane", family_name: "Smith")
520514

0 commit comments

Comments
 (0)