Fix trash cleanup deleting records before the retention period ends
Merged
AS
2d ago+56+56+01234567890123456789-10-10-01234567890123456789
Fixes #30460.
The trash cleanup cutoff was today's midnight UTC minus trashRetentionDays - 1 days, so everything soft-deleted during a day was permanently deleted at the 00:10 run on day trashRetentionDays. Records deleted late in the day were kept almost a day less than the setting: 13 days 0 h 20 min with the default of 14, and 11 minutes with a retention of 1 day.
Change
- The cutoff is now midnight UTC minus
trashRetentionDaysdays, so a record stays in the trash for at leasttrashRetentionDaysfull days and is deleted at the first daily run after that (at most one day later). - It uses
setUTCDate/getUTCDatethroughout. The old code mixedsetUTCHourswith local-timesetDate, so the result depended on the server's time zone. - The calculation moved to
computeTrashCleanupCutoffDateintrash-cleanup/utilsso it can be unit-tested.
Tests
- New
compute-trash-cleanup-cutoff-date.util.spec.ts(fake timers): for retentions of 1, 14 and 30 days, a record deleted at 23:59:59.999 survives the cleanup run on daytrashRetentionDaysand is deleted on the next run. The "survives" cases fail on the old code. - Also verified end to end on the published v2.58.0 image with the fix applied in the worker. Run reports: https://github.com/Asmodeus14/ChronoStack/tree/main/docs/launch/outreach/twenty.