forked from mtusi2026/mtusi2026lab4
fix: harden attachment cleanup
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user