|
4 | 4 | "attachment_cache", |
5 | 5 | "store_attachments_for_event", |
6 | 6 | "get_attachments_for_event", |
7 | | - "delete_ratelimited_attachments", |
| 7 | + "delete_cached_and_ratelimited_attachments", |
8 | 8 | "CachedAttachment", |
9 | 9 | "MissingAttachmentChunks", |
10 | 10 | ] |
@@ -70,21 +70,30 @@ def get_attachments_for_event(event: Any) -> Generator[CachedAttachment]: |
70 | 70 | return attachment_cache.get(cache_key) |
71 | 71 |
|
72 | 72 |
|
73 | | -def delete_ratelimited_attachments( |
| 73 | +@sentry_sdk.trace |
| 74 | +def delete_cached_and_ratelimited_attachments( |
74 | 75 | project: Project, event: Any, attachments: list[CachedAttachment] |
75 | 76 | ): |
76 | 77 | """ |
77 | | - This deletes all the attachments that are `rate_limited` from `objectstore` in case they are stored, |
78 | | - and it will also remove all the attachments from the attachments cache as well. |
| 78 | + This deletes all attachment payloads and metadata from the attachment cache |
| 79 | + (if those are stored there), as well as delete all the `rate_limited` |
| 80 | + attachments from the `objectstore`. |
| 81 | + Non-ratelimited attachments which are already stored in `objectstore` will |
| 82 | + be retained there for long-term storage. |
79 | 83 | """ |
80 | 84 | client: ObjectstoreClient | None = None |
81 | 85 | for attachment in attachments: |
| 86 | + # deletes from objectstore if no long-term storage is desired |
82 | 87 | if attachment.rate_limited and attachment.stored_id: |
83 | 88 | if client is None: |
84 | 89 | client = get_attachments_client().for_project(project.organization_id, project.id) |
85 | 90 | client.delete(attachment.stored_id) |
86 | 91 |
|
87 | | - # all other attachments which only exist in the cache but are not stored will |
88 | | - # be cleaned up here: |
| 92 | + # unconditionally deletes any payloads from the attachment cache |
| 93 | + attachment.delete() |
| 94 | + |
| 95 | + # this cleans up the metadata from the attachments cache: |
| 96 | + # any payloads living in the attachments cache have been cleared by the |
| 97 | + # `attachment.delete()` call above. |
89 | 98 | cache_key = cache_key_for_event(event) |
90 | 99 | attachment_cache.delete(cache_key) |
0 commit comments