def count(self, **kwargs): "Just like 'get' but returns the count instead of the list. If a datetime is provided" key = self.count_key(kwargs) count = self.mc.get(key) if count is None: if self.soft_delete_field: kwargs = dict_merge(kwargs, {self.soft_delete_field: False}) count = self.backing_store.count(kwargs) self.mc.set(key, count) return count
def count(self, **kwargs): "Just like 'get' but returns the count instead of the list. If a datetime is provided" key = self.count_key(kwargs) count = self.mc.get(key) if count is None: if self.soft_delete_field: kwargs = dict_merge(kwargs, { self.soft_delete_field: False }) count = self.backing_store.count(kwargs) self.mc.set(key, count) return count
def _counts_from_db(self, freq, timestamps, filter_args): counts = dict((aggregator(freq, t), 0) for t in timestamps) start = to_datetime(aggregator(freq, timestamps[0])) end = to_datetime(aggregator(freq, timestamps[-1]) + RELATIVEDELTA[freq]) if self.soft_delete_field: filter_args = dict_merge(filter_args, { self.soft_delete_field: False }) timestamps_to_count = self.backing_store.timestamps(filter_args, start, end) counts.update(Counter([aggregator(freq, dt) for dt in timestamps_to_count])) for timestamp, count in counts.items(): log.debug("Setting cached count of %d for %s", count, timestamp) self.mc.set(self.count_key(filter_args, freq, timestamp), count) return counts
def _counts_from_db(self, freq, timestamps, filter_args): counts = dict((aggregator(freq, t), 0) for t in timestamps) start = to_datetime(aggregator(freq, timestamps[0])) end = to_datetime( aggregator(freq, timestamps[-1]) + RELATIVEDELTA[freq]) if self.soft_delete_field: filter_args = dict_merge(filter_args, {self.soft_delete_field: False}) timestamps_to_count = self.backing_store.timestamps( filter_args, start, end) counts.update( Counter([aggregator(freq, dt) for dt in timestamps_to_count])) for timestamp, count in counts.items(): log.debug("Setting cached count of %d for %s", count, timestamp) self.mc.set(self.count_key(filter_args, freq, timestamp), count) return counts
def timestamps(self, filter_args, start, end): field = self.manager.model.cache.timestamp_field date_filter = {field + '__gte': start, field + '__lt': end} return self.manager.filter( **dict_merge(filter_args, date_filter)).values_list(field, flat=True)
def timestamps(self, filter_args, start, end): field = self.manager.model.cache.timestamp_field date_filter = { field + '__gte': start, field + '__lt': end } return self.manager.filter(**dict_merge(filter_args, date_filter)).values_list(field, flat=True)