Skip to content

Commit 454af71

Browse files
committed
acc denied on MANIFEST was coming up 4 and 6 times per second.... memoize
1 parent 7d82d3f commit 454af71

File tree

1 file changed

+18
-1
lines changed
  • hubblestack/extmods/utils

1 file changed

+18
-1
lines changed

hubblestack/extmods/utils/s3.py

+18-1
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,31 @@
2222
import salt.utils.files
2323
import salt.utils.hashutils
2424
import salt.utils.xmlutil as xml
25+
import time
2526
from salt._compat import ElementTree as ET
2627
from salt.exceptions import CommandExecutionError
2728
from salt.ext.six.moves.urllib.parse import quote as _quote # pylint: disable=import-error,no-name-in-module
2829
from salt.ext import six
2930

3031
log = logging.getLogger(__name__)
3132

32-
33+
def thirty_second_memoize(f):
34+
memo = dict()
35+
def inner(*a, **kw):
36+
k = '-'.join([ str(x) for x in a ] + [ str(kw[x]) for x in sorted(kw) ])
37+
now = time.time()
38+
if k in memo:
39+
v,t = memo[k]
40+
if now - t < 30:
41+
log_k = kw.get('path', k)
42+
log.info('returning memoized result for %s', log_k)
43+
return v
44+
v = f(*a, **kw)
45+
memo[k] = (v,now)
46+
return v
47+
return inner
48+
49+
@thirty_second_memoize
3350
def query(key, keyid, method='GET', params=None, headers=None,
3451
requesturl=None, return_url=False, bucket=None, service_url=None,
3552
path='', return_bin=False, action=None, local_file=None,

0 commit comments

Comments
 (0)