Skip to content

Commit

Permalink
Issue mozilla-mobile#25: Add request_handler.readCacheVenueIterableDe…
Browse files Browse the repository at this point in the history
…tails.
  • Loading branch information
mcomella committed Jan 28, 2017
1 parent ac68145 commit e172010
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def _findTablePrefix():
_events = "events"
_searches = "searches"
_locations = "locations"
_cache = "cache"

# number of seconds after a search in a given area that it should be cached.
searchCacheExpiry = 60 * 60 * 20 # s
Expand All @@ -34,6 +35,7 @@ def _findTablePrefix():
eventsTable = _tablePrefix + _events
searchesTable = _tablePrefix + _searches
locationsTable = _tablePrefix + _venues + '/' + _locations
cacheTable = _tablePrefix + _venues + '/' + _cache

statusTable = "api_availability"

Expand Down
23 changes: 22 additions & 1 deletion app/request_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from config import FIREBASE_CONFIG
from app.constants import \
venuesTable, venueSearchRadius, venueSearchNumber, \
eventsTable, \
eventsTable, cacheTable, \
searchesTable, searchCacheExpiry, searchCacheRadius, \
konaLatLng, calendarInfo

Expand Down Expand Up @@ -89,6 +89,27 @@ def readCachedVenueDetails(key):
except Exception:
log.error("Error fetching cached venue details for " + key)

def readCachedVenueIterableDetails(place_ids):
"""Retrieves the cache objects matching the given place IDs.
This method retrieves the whole cache/ child when making a call so call sparingly.
We do this because it's slow to make network requests for each child individually.
To pull down less data, you can use `readCacheVenueDetails`.
:param place_ids: Iterable of place_ids
:return: a list of cache objects. If a place_id is not in the cache, it will be dropped from the results.
"""
out = []
try:
cache = db.child(cacheTable).get().val()
for place_id in place_ids:
if place_id not in cache: continue
out.append(cache[place_id])
except Exception:
log.error("Error fetching cached venue details for " + place_id)

return out

def readCachedVenueIdentifiers(cache):
if cache is not None:
return cache.get("identifiers", None)
Expand Down

0 comments on commit e172010

Please sign in to comment.