Skip to content

Commit d7cbcd8

Browse files
committed
Use delete_all instead of destroy_all
This should improve performance of the endpoint in the testing API used to clear out a team by avoiding the need to run the Rails callbacks.
1 parent 3273448 commit d7cbcd8

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

app/controllers/api/testing/teams_controller.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,9 @@ def destroy
5959
log_destroy(Consent.where(team:))
6060
log_destroy(Triage.where(team:))
6161

62-
Patient
63-
.where(id: patient_ids)
64-
.includes(:parents)
65-
.in_batches { log_destroy(it) }
62+
log_destroy(ParentRelationship.where(patient_id: patient_ids))
63+
log_destroy(Patient.where(id: patient_ids))
64+
log_destroy(Parent.where.missing(:parent_relationships))
6665

6766
batches = Batch.where(team:)
6867
log_destroy(VaccinationRecord.where(batch: batches))
@@ -101,7 +100,7 @@ def destroy
101100
def log_destroy(query)
102101
where_clause = query.where_clause
103102
@log_time ||= Time.zone.now
104-
query.destroy_all
103+
query.delete_all
105104
response.stream.write(
106105
"#{query.model.name}.where(#{where_clause.to_h}): #{Time.zone.now - @log_time}s\n"
107106
)

0 commit comments

Comments
 (0)