Skip to content

Commit 079fccf

Browse files
Remove extra logging from destroy_locations
It was decided that this level of logging was unnecessary after `PatientDeleter` was introduced, particularly because of the introduction of the unit test which checks which FK relationships are deleted by the `PatientDeleter` Jira-Issue: MAV-7067
1 parent 0256df0 commit 079fccf

1 file changed

Lines changed: 62 additions & 86 deletions

File tree

app/controllers/api/testing/teams_controller.rb

Lines changed: 62 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -14,70 +14,64 @@ def destroy
1414

1515
@start_time = Time.zone.now
1616

17-
log_destroy(CohortImport.where(team:))
18-
log_destroy(ImmunisationImport.where(team:))
19-
log_destroy(ClassImport.where(team:))
20-
21-
log_destroy(Consent.where(team:))
22-
log_destroy(ArchiveReason.where(team:))
23-
log_destroy(ImportantNotice.where(team:))
24-
25-
log_destroy(
26-
NotifyLogEntry.joins(:team_location).where(team_location: { team_id: })
27-
)
28-
log_destroy(ConsentForm.for_team(team))
29-
30-
log_destroy(ClinicNotification.where(team_id:))
31-
log_destroy(
32-
ConsentNotification.joins(session: :team_location).where(
33-
team_location: {
34-
team_id:
35-
}
36-
)
37-
)
38-
log_destroy(
39-
ConsentNotification.joins(:team_location).where(
40-
team_location: {
41-
team_id:
42-
}
43-
)
44-
)
45-
log_destroy(
46-
SessionNotification.joins(session: :team_location).where(
47-
team_location: {
48-
team_id:
49-
}
50-
)
51-
)
52-
log_destroy(
53-
VaccinationRecord.joins(session: :team_location).where(
54-
team_locations: {
55-
team_id:
56-
}
57-
)
58-
)
17+
CohortImport.where(team:).delete_all
18+
ImmunisationImport.where(team:).delete_all
19+
ClassImport.where(team:).delete_all
20+
21+
Consent.where(team:).delete_all
22+
ArchiveReason.where(team:).delete_all
23+
ImportantNotice.where(team:).delete_all
24+
25+
NotifyLogEntry
26+
.joins(:team_location)
27+
.where(team_location: { team_id: })
28+
.delete_all
29+
30+
ConsentForm.for_team(team).delete_all
31+
32+
ClinicNotification.where(team_id:).delete_all
33+
34+
ConsentNotification
35+
.joins(session: :team_location)
36+
.where(team_location: { team_id: })
37+
.delete_all
38+
39+
ConsentNotification
40+
.joins(:team_location)
41+
.where(team_location: { team_id: })
42+
.delete_all
43+
44+
SessionNotification
45+
.joins(session: :team_location)
46+
.where(team_location: { team_id: })
47+
.delete_all
48+
49+
VaccinationRecord
50+
.joins(session: :team_location)
51+
.where(team_locations: { team_id: })
52+
.delete_all
5953

6054
# In local dev we can end up with NotifyLogEntries without a patient
61-
log_destroy(NotifyLogEntry.where(patient_id: nil))
55+
NotifyLogEntry.where(patient_id: nil).delete_all
6256

63-
log_destroy_patients(patients: team.patients)
57+
PatientDeleter.call(patients: team.patients)
6458

65-
log_destroy(Batch.where(team:))
59+
Batch.where(team:).delete_all
6660

67-
log_destroy(
68-
VaccinationRecord.where(performed_ods_code: team.organisation.ods_code)
69-
)
61+
VaccinationRecord.where(
62+
performed_ods_code: team.organisation.ods_code
63+
).delete_all
7064

71-
log_destroy(Triage.where(team:))
65+
Triage.where(team:).delete_all
7266

7367
TeamCachedCounts.new(team).reset_all!
7468

75-
log_destroy(Session.for_team(team))
69+
Session.for_team(team).delete_all
7670

7771
unless keep_itself
78-
log_destroy(TeamLocation.where(team:))
79-
log_destroy(Subteam.where(team:))
80-
log_destroy(Team.where(id: team.id))
72+
TeamLocation.where(team:).delete_all
73+
Subteam.where(team:).delete_all
74+
Team.where(id: team.id).delete_all
8175
end
8276

8377
response.stream.write "Done"
@@ -103,28 +97,28 @@ def destroy_locations
10397

10498
location_ids_to_delete = locations.pluck(:id)
10599

106-
log_destroy(AttendanceRecord.where(location_id: location_ids_to_delete))
107-
log_destroy(ClassImport.where(location_id: location_ids_to_delete))
108-
log_destroy(GillickAssessment.where(location_id: location_ids_to_delete))
109-
log_destroy(PatientLocation.where(location_id: location_ids_to_delete))
110-
log_destroy(PreScreening.where(location_id: location_ids_to_delete))
100+
AttendanceRecord.where(location_id: location_ids_to_delete).delete_all
101+
ClassImport.where(location_id: location_ids_to_delete).delete_all
102+
GillickAssessment.where(location_id: location_ids_to_delete).delete_all
103+
PatientLocation.where(location_id: location_ids_to_delete).delete_all
104+
PreScreening.where(location_id: location_ids_to_delete).delete_all
111105

112106
team_location_ids =
113107
TeamLocation.where(location_id: location_ids_to_delete).pluck(:id)
114-
log_destroy(Session.where(team_location_id: team_location_ids))
115-
log_destroy(TeamLocation.where(location_id: location_ids_to_delete))
108+
Session.where(team_location_id: team_location_ids).delete_all
109+
TeamLocation.where(location_id: location_ids_to_delete).delete_all
116110

117-
log_destroy(VaccinationRecord.where(location_id: location_ids_to_delete))
111+
VaccinationRecord.where(location_id: location_ids_to_delete).delete_all
118112

119113
location_year_group_ids =
120114
Location::YearGroup.where(location_id: location_ids_to_delete).pluck(:id)
121-
log_destroy(
122-
Location::ProgrammeYearGroup.where(
123-
location_year_group_id: location_year_group_ids
124-
)
125-
)
126-
log_destroy(Location::YearGroup.where(location_id: location_ids_to_delete))
127-
log_destroy(locations)
115+
116+
Location::ProgrammeYearGroup.where(
117+
location_year_group_id: location_year_group_ids
118+
).delete_all
119+
120+
Location::YearGroup.where(location_id: location_ids_to_delete).delete_all
121+
locations.delete_all
128122

129123
if keep_base_locations
130124
Location.where(id: location_ids, site: "A").update_all(site: nil)
@@ -137,22 +131,4 @@ def destroy_locations
137131
ensure
138132
response.stream.close
139133
end
140-
141-
private
142-
143-
def log_destroy(query)
144-
where_clause = query.where_clause
145-
@log_time ||= Time.zone.now
146-
query.delete_all
147-
response.stream.write(
148-
"#{query.model.name}.where(#{where_clause.to_h}): #{Time.zone.now - @log_time}s\n"
149-
)
150-
@log_time = Time.zone.now
151-
end
152-
153-
def log_destroy_patients(patients:)
154-
PatientDeleter.call(patients:)
155-
response.stream.write("PatientDeleter.call(patients: team.patients)")
156-
@log_time = Time.zone.now
157-
end
158134
end

0 commit comments

Comments
 (0)