Skip to content

Commit

Permalink
Don't serialize and cache GetSeriesCatalogForBox2
Browse files Browse the repository at this point in the history
For larger areas of interest, this call returns a very large
number of results, serializing all of which is futile and
expensive.
  • Loading branch information
rajadain committed Oct 23, 2017
1 parent 834231b commit 76e0eca
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions src/mmw/apps/bigcz/clients/cuahsi/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,17 +201,9 @@ def group_series_by_location(series):
return records


def make_request(request, expiry, **kwargs):
key = 'bigcz_{}_{}'.format(request.method.name,
hash(frozenset(kwargs.items())))
cached = cache.get(key)
if cached:
return cached

def make_request(request, **kwargs):
try:
response = recursive_asdict(request(**kwargs))
cache.set(key, response, timeout=expiry)
return response
return request(**kwargs)
except URLError, e:
if isinstance(e.reason, timeout):
raise RequestTimedOutError()
Expand All @@ -222,15 +214,21 @@ def make_request(request, expiry, **kwargs):


def get_services_in_box(box):
key = 'bigcz_cuahsi_GetServicesInBox2_{}'.format(hash(box))
cached = cache.get(key)
if cached:
return cached

result = make_request(client.service.GetServicesInBox2,
604800, # Cache for one week
xmin=box.xmin,
xmax=box.xmax,
ymin=box.ymin,
ymax=box.ymax)

try:
return result['ServiceInfo']
data = recursive_asdict(result)
cache.set(key, data['ServiceInfo'], timeout=604800) # Cache for 1 week
return data['ServiceInfo']
except KeyError:
# Missing key may indicate a server-side error
raise ValueError(result)
Expand All @@ -244,7 +242,6 @@ def get_series_catalog_in_box(box, from_date, to_date, networkIDs):
to_date = to_date or DATE_MAX

result = make_request(client.service.GetSeriesCatalogForBox2,
300, # Cache for 5 minutes
xmin=box.xmin,
xmax=box.xmax,
ymin=box.ymin,
Expand Down

0 comments on commit 76e0eca

Please sign in to comment.