Skip to content

Commit

Permalink
corrected an issue where it didn't append missing keys to the selecte…
Browse files Browse the repository at this point in the history
…d results
  • Loading branch information
dcramer committed Jan 21, 2008
1 parent 943c0ad commit d2bcb21
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions cache/query.py
Expand Up @@ -112,17 +112,18 @@ def _get_queryset_from_cache(self, cache_object):

def _get_objects_for_keys(self, model, keys):
# First we fetch any keys that we can from the cache
results = cache.get_many([get_cache_key_for_pk(model, k) for k in keys]).values()
results = list(cache.get_many([get_cache_key_for_pk(model, k) for k in keys]).values())

# Now we need to compute which keys weren't present in the cache
result_pks = [k.pk for k in results]
missing = [k for k in keys if k not in result_pks]
# Query for any missing objects
# TODO: should this only be doing the cache.set if it's from a CachedModel?
# if not then we need to expire it, hook signals?
objects = model._default_manager.filter(pk__in=missing)
objects = list(model._default_manager.filter(pk__in=missing))
for o in objects:
cache.set(o.cache_key, o)
results.extend(objects)

# Do a simple len() lookup (maybe we shouldn't rely on it returning the right
# number of objects
Expand Down

0 comments on commit d2bcb21

Please sign in to comment.