2
2
# License, v. 2.0. If a copy of the MPL was not distributed with this
3
3
# file, you can obtain one at http://mozilla.org/MPL/2.0/.
4
4
5
- import hashlib
6
5
import time
7
6
from io import BytesIO
8
7
from gzip import GzipFile
14
13
from botocore .exceptions import ClientError
15
14
16
15
from django .conf import settings
17
- from django .utils .encoding import force_bytes
18
16
19
17
from tecken .base .decorators import cache_memoize
20
18
from tecken .s3 import S3Bucket
@@ -78,10 +76,6 @@ def wrapper(self, *args, **kwargs):
78
76
return wrapper
79
77
80
78
81
- def make_symbol_cache_key (bucket_name , key ):
82
- return hashlib .md5 (force_bytes (f'symbol:{ bucket_name } :{ key } ' )).hexdigest ()
83
-
84
-
85
79
@metrics .timer_decorator ('symboldownloader_exists' )
86
80
@cache_memoize (
87
81
settings .SYMBOLDOWNLOAD_EXISTS_TTL_SECONDS ,
@@ -232,7 +226,7 @@ def _make_key(prefix, symbol, debugid, filename):
232
226
filename ,
233
227
)
234
228
235
- def _get (self , symbol , debugid , filename ):
229
+ def _get (self , symbol , debugid , filename , refresh_cache = False ):
236
230
"""Return a dict if the symbol can be found. The dict will
237
231
either be `{'url': ...}` or `{'buckey_name': ..., 'key': ...}`
238
232
depending on if the symbol was found a public bucket or a
@@ -248,7 +242,9 @@ def _get(self, symbol, debugid, filename):
248
242
# If it's a private bucket we use boto3.
249
243
250
244
key = self ._make_key (prefix , symbol , debugid , filename )
251
- if not exists_in_source (source , key ):
245
+ if not exists_in_source (
246
+ source , key , _refresh = refresh_cache
247
+ ):
252
248
continue
253
249
254
250
logger .debug (
@@ -276,7 +272,7 @@ def _get(self, symbol, debugid, filename):
276
272
logger .debug (
277
273
f'Looking for symbol file by URL { file_url !r} '
278
274
)
279
- if check_url_head (file_url ):
275
+ if check_url_head (file_url , _refresh = refresh_cache ):
280
276
return {'url' : file_url , 'source' : source }
281
277
282
278
def _get_stream (self , symbol , debugid , filename ):
@@ -404,16 +400,20 @@ def _get_stream(self, symbol, debugid, filename):
404
400
raise SymbolNotFound (symbol , debugid , filename )
405
401
406
402
@set_time_took
407
- def has_symbol (self , symbol , debugid , filename ):
403
+ def has_symbol (self , symbol , debugid , filename , refresh_cache = False ):
408
404
"""return True if the symbol can be found, False if not
409
405
found in any of the URLs provided."""
410
- return bool (self ._get (symbol , debugid , filename ))
406
+ return bool (self ._get (
407
+ symbol , debugid , filename , refresh_cache = refresh_cache ,
408
+ ))
411
409
412
410
@set_time_took
413
- def get_symbol_url (self , symbol , debugid , filename ):
411
+ def get_symbol_url (self , symbol , debugid , filename , refresh_cache = False ):
414
412
"""return the redirect URL or None. If we return None
415
413
it means we can't find the object in any of the URLs provided."""
416
- found = self ._get (symbol , debugid , filename )
414
+ found = self ._get (
415
+ symbol , debugid , filename , refresh_cache = refresh_cache
416
+ )
417
417
if found :
418
418
if 'url' in found :
419
419
return found ['url' ]
0 commit comments