Closed garethrees closed 3 years ago
This is due to some requests having more than one very_overdue
InfoRequestEvent:
=> SELECT info_request_id, COUNT(*) FROM info_request_events WHERE event_type = 'very_overdue' GROUP BY info_request_id;
info_request_id | count
-----------------+-------
2848 | 2
...
It appears before 2017-04-21, these events were duplicated - with exact same created_at/updated_at timestamps. So we could delete duplicated events or something like this should work:
diff --git a/app/models/info_request.rb b/app/models/info_request.rb
index c3494e7246..c574c37109 100644
--- a/app/models/info_request.rb
+++ b/app/models/info_request.rb
@@ -673,7 +673,8 @@ class InfoRequest < ApplicationRecord
FROM info_request_events
WHERE info_request_id = info_requests.id
AND event_type = ?
- AND created_at > info_requests.#{date_field})
+ AND created_at > info_requests.#{date_field}
+ LIMIT 1)
IS NULL",
false,
'waiting_response',
This shows the duplciated records:
SELECT ire1.id, ire2.id, ire1.info_request_id, ire1.created_at, ire2.created_at, ire1.updated_at, ire2.updated_at
FROM info_request_events ire1
INNER JOIN info_request_events ire2 ON (
ire1.event_type = ire2.event_type AND
ire1.id < ire2.id AND
ire1.info_request_id = ire2.info_request_id
)
WHERE ire1.event_type = 'very_overdue';
I haven't dug into this, but I don't see why a request shouldn't be able to have 2 very_overdue
events. We account for clarification requests (which reset the clock), so the chain of events could plausibly be:
I don't know why we'd get 2 with an identical timestamp though. The SQL snippet gives a syntax error.
The SQL snippet gives a syntax error.
Stray comma - fixed
Oh I wonder if this is caused by running bundle exec rake temp:backload_very_overdue_info_request_events
twice
Oh I wonder if this is caused by running
bundle exec rake temp:backload_very_overdue_info_request_events
twice
Sounds probable – should be able to test locally?
Couldn't replicate the issue locally. Instead I've used the rails console to remvoe duplciate InfoRequestEvent
records where all the attributes (excpet ID
of course) match and have deleted.
Script now runs without erroring.