|
1 | 1 | from __future__ import annotations
|
2 | 2 |
|
3 |
| -import errno |
4 | 3 | import logging
|
5 |
| -import os |
6 | 4 | import zipfile
|
7 | 5 | from contextlib import contextmanager
|
8 | 6 | from hashlib import sha1
|
|
12 | 10 | from urllib.parse import urlunsplit
|
13 | 11 |
|
14 | 12 | import sentry_sdk
|
15 |
| -from django.core.files.base import File as FileObj |
16 | 13 | from django.db import models, router
|
17 | 14 |
|
18 |
| -from sentry import options |
19 | 15 | from sentry.backup.scopes import RelocationScope
|
20 | 16 | from sentry.db.models import (
|
21 | 17 | BoundedBigIntegerField,
|
|
28 | 24 | from sentry.db.models.manager.base import BaseManager
|
29 | 25 | from sentry.models.distribution import Distribution
|
30 | 26 | from sentry.models.files.file import File
|
31 |
| -from sentry.models.files.utils import clear_cached_files |
32 | 27 | from sentry.models.release import Release
|
33 |
| -from sentry.utils import json, metrics |
| 28 | +from sentry.utils import json |
34 | 29 | from sentry.utils.db import atomic_transaction
|
35 | 30 | from sentry.utils.hashlib import sha1_text
|
36 | 31 | from sentry.utils.urls import urlsplit_best_effort
|
@@ -90,8 +85,6 @@ class ReleaseFile(Model):
|
90 | 85 | objects: ClassVar[BaseManager[Self]] = BaseManager() # The default manager.
|
91 | 86 | public_objects: ClassVar[PublicReleaseFileManager] = PublicReleaseFileManager()
|
92 | 87 |
|
93 |
| - cache: ClassVar[ReleaseFileCache] |
94 |
| - |
95 | 88 | class Meta:
|
96 | 89 | unique_together = (("release_id", "ident"),)
|
97 | 90 | indexes = (models.Index(fields=("release_id", "name")),)
|
@@ -152,48 +145,6 @@ def normalize(cls, url):
|
152 | 145 | return urls
|
153 | 146 |
|
154 | 147 |
|
155 |
| -class ReleaseFileCache: |
156 |
| - @property |
157 |
| - def cache_path(self): |
158 |
| - return options.get("releasefile.cache-path") |
159 |
| - |
160 |
| - def getfile(self, releasefile): |
161 |
| - cutoff = options.get("releasefile.cache-limit") |
162 |
| - file_size = releasefile.file.size |
163 |
| - if file_size < cutoff: |
164 |
| - metrics.distribution( |
165 |
| - "release_file.cache.get.size", file_size, tags={"cutoff": True}, unit="byte" |
166 |
| - ) |
167 |
| - return releasefile.file.getfile() |
168 |
| - |
169 |
| - file_id = str(releasefile.file.id) |
170 |
| - organization_id = str(releasefile.organization_id) |
171 |
| - file_path = os.path.join(self.cache_path, organization_id, file_id) |
172 |
| - |
173 |
| - hit = True |
174 |
| - try: |
175 |
| - os.stat(file_path) |
176 |
| - except OSError as e: |
177 |
| - if e.errno != errno.ENOENT: |
178 |
| - raise |
179 |
| - releasefile.file.save_to(file_path) |
180 |
| - hit = False |
181 |
| - |
182 |
| - metrics.distribution( |
183 |
| - "release_file.cache.get.size", |
184 |
| - file_size, |
185 |
| - tags={"hit": hit, "cutoff": False}, |
186 |
| - unit="byte", |
187 |
| - ) |
188 |
| - return FileObj(open(file_path, "rb")) |
189 |
| - |
190 |
| - def clear_old_entries(self): |
191 |
| - clear_cached_files(self.cache_path) |
192 |
| - |
193 |
| - |
194 |
| -ReleaseFile.cache = ReleaseFileCache() |
195 |
| - |
196 |
| - |
197 | 148 | class ReleaseArchive:
|
198 | 149 | """Read-only view of uploaded ZIP-archive of release files"""
|
199 | 150 |
|
@@ -288,17 +239,14 @@ def __init__(self, release: Release, dist: Distribution | None, **filter_args):
|
288 | 239 | self._ident = ReleaseFile.get_ident(ARTIFACT_INDEX_FILENAME, dist and dist.name)
|
289 | 240 | self._filter_args = filter_args # Extra constraints on artifact index release file
|
290 | 241 |
|
291 |
| - def readable_data(self, use_cache: bool) -> dict | None: |
| 242 | + def readable_data(self) -> dict | None: |
292 | 243 | """Simple read, no synchronization necessary"""
|
293 | 244 | try:
|
294 | 245 | releasefile = self._releasefile_qs()[0]
|
295 | 246 | except IndexError:
|
296 | 247 | return None
|
297 | 248 | else:
|
298 |
| - if use_cache: |
299 |
| - fp = ReleaseFile.cache.getfile(releasefile) |
300 |
| - else: |
301 |
| - fp = releasefile.file.getfile() |
| 249 | + fp = releasefile.file.getfile() |
302 | 250 | with fp:
|
303 | 251 | return json.load(fp)
|
304 | 252 |
|
@@ -384,12 +332,10 @@ def _key_fields(self):
|
384 | 332 |
|
385 | 333 |
|
386 | 334 | @sentry_sdk.tracing.trace
|
387 |
| -def read_artifact_index( |
388 |
| - release: Release, dist: Distribution | None, use_cache: bool = False, **filter_args |
389 |
| -) -> dict | None: |
| 335 | +def read_artifact_index(release: Release, dist: Distribution | None, **filter_args) -> dict | None: |
390 | 336 | """Get index data"""
|
391 | 337 | guard = _ArtifactIndexGuard(release, dist, **filter_args)
|
392 |
| - return guard.readable_data(use_cache) |
| 338 | + return guard.readable_data() |
393 | 339 |
|
394 | 340 |
|
395 | 341 | def _compute_sha1(archive: ReleaseArchive, url: str) -> str:
|
|
0 commit comments