fix: harden attachment cleanup

This commit is contained in:
2026-10-09 13:27:58 +03:00
parent f8c31de7c0
commit 3fde1c324c
8 changed files with 134 additions and 24 deletions
+13 -5
View File
@@ -121,13 +121,21 @@ func (s *metadataStub) AttachmentExistsByObjectKey(_ context.Context, key string
return exists, nil
}
func (s *metadataStub) ClaimAttachmentForDeletion(_ context.Context, id string, cutoff time.Time) (bool, error) {
func (s *metadataStub) ClaimAttachmentForDeletion(_ context.Context, candidate model.Attachment, cutoff time.Time) (bool, error) {
for key, item := range s.items {
if item.ID == id && !item.CreatedAt.After(cutoff) && !item.Referenced {
item.Status = model.AttachmentDeleting
s.items[key] = item
return true, nil
if item.ID != candidate.ID || item.Status != candidate.Status || item.Referenced {
continue
}
age := item.CreatedAt
if item.Status == model.AttachmentReady && item.ReadyAt != nil {
age = *item.ReadyAt
}
if age.After(cutoff) {
return false, nil
}
item.Status = model.AttachmentDeleting
s.items[key] = item
return true, nil
}
return false, nil
}