Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
query_cache: PEP-8 and whitespace tweaks.
Browse files Browse the repository at this point in the history
  • Loading branch information
spladug committed Oct 10, 2012
1 parent 9684517 commit 5c2c0e6
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions r2/r2/models/query_cache.py
Expand Up @@ -35,11 +35,13 @@
from r2.lib.utils import flatten, to36
from r2.lib.db.tdb_cassandra import json


CONNECTION_POOL = g.cassandra_pools['main']
PRUNE_CHANCE = g.querycache_prune_chance
MAX_CACHED_ITEMS = 1000
LOG = g.log


class ThingTupleComparator(object):
def __init__(self, sorts):
self.sorts = sorts
Expand Down Expand Up @@ -151,11 +153,12 @@ def _prune(self, mutator):

if extraneous_ids:
self.model.remove_if_unchanged(mutator, self.key,
extraneous_ids, self.timestamps)
extraneous_ids, self.timestamps)

cf_name = self.model.__name__
query_name = self.key.split('.')[0]
counter = g.stats.get_counter('cache.%s.%s' % (cf_name, query_name))
counter_key = "cache.%s.%s" % (cf_name, query_name)
counter = g.stats.get_counter(counter_key)
if counter:
counter.increment('pruned', delta=len(extraneous_ids))

Expand Down Expand Up @@ -188,8 +191,10 @@ def __repr__(self):
class SqlCachedQuery(CachedQuery):
def __init__(self, model, key, query, filter_fn):
self.query = query
self.query._limit = MAX_CACHED_ITEMS # .update() should only get as many items as we need
super(SqlCachedQuery, self).__init__(model, key, query._sort, filter_fn)
# ensure that .update() doesn't fetch more items than we need
self.query._limit = MAX_CACHED_ITEMS
super(SqlCachedQuery, self).__init__(model, key, query._sort,
filter_fn)

def update(self):
things = list(self.query)
Expand Down

0 comments on commit 5c2c0e6

Please sign in to comment.