Skip to content

Commit

Permalink
responding to @bfalling CR, comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mekarpeles authored and root committed Aug 21, 2018
1 parent 80b03cd commit 99ba7d2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion openlibrary/core/cache.py
Expand Up @@ -25,7 +25,7 @@
HOUR = 60 * 60
DAY = HOUR * 24
HALF_DAY = HOUR * 12
ONE_WEEK = HALF_DAY * 2 * 7
ONE_WEEK = DAY * 7


class memcache_memoize:
Expand Down
7 changes: 7 additions & 0 deletions openlibrary/plugins/openlibrary/code.py
Expand Up @@ -772,6 +772,13 @@ def GET(self):
return result

def is_bot():
"""Generated on ol-www1 within /var/log/nginx with:
cat access.log | grep -oh "; \w*[bB]ot" | sort --unique | awk '{print tolower($2)}'
cat access.log | grep -oh "; \w*[sS]pider" | sort --unique | awk '{print tolower($2)}'
Manually removed singleton `bot` (to avoid overly complex grep regex)
"""
user_agent_bots = [
'sputnikbot', 'dotbot', 'semrushbot',
'googlebot', 'yandexbot', 'monsidobot', 'kazbtbot',
Expand Down
13 changes: 9 additions & 4 deletions openlibrary/plugins/upstream/code.py
Expand Up @@ -132,16 +132,21 @@ def cached_get_amazon_metadata(*args, **kwargs):
"""If the cached data is `None`, likely a 503 throttling occurred on
Amazon's side. Try again to fetch the value instead of using the
cached value. It may 503 again, in which case the next access of
this page will trigger another re-cache. If the book has no price
data, then {"price": None} will be cached will will not trigger a
re-cache (only the value `None` will)
this page will trigger another re-cache. If the amazon API call
succeeds but the book has no price data, then {"price": None} will
be cached as to not trigger a re-cache (only the value `None`
will cause re-cache)
"""
# fetch/compose a cache controller obj for
# "upstream.code._get_amazon_metadata"
memoized_get_amazon_metadata = cache.memcache_memoize(
_get_amazon_metadata, "upstream.code._get_amazon_metadata",
timeout=cache.ONE_WEEK)
# fetch cached value from this controller
result = memoized_get_amazon_metadata(*args, **kwargs)
if result is None:
# recache / update this controller's cached value
# (corresponding to these input args)
result = memoized_get_amazon_metadata.update(*args, **kwargs)[0]
return result

Expand Down

0 comments on commit 99ba7d2

Please sign in to comment.