def get_cached_downvotes(content_cls): kind = content_cls.__name__.lower() downvotes = g.cache.get(self.vote_cache_key(kind)) if downvotes is None: vote_cls = Vote.rel(Account, content_cls) downvotes = len(list(vote_cls._query(Vote.c._thing1_id == self._id, Vote.c._name == str(-1)))) g.cache.set(self.vote_cache_key(kind), downvotes) return downvotes
def get_cached_downvotes(content_cls): kind = content_cls.__name__.lower() cache_key = self.downvote_cache_key(kind) downvotes = g.cache.get(cache_key) if downvotes is None: vote_cls = Vote.rel(Account, content_cls) # Get a count of content_cls downvotes type = tdb.rel_types_id[vote_cls._type_id] # rt = rel table # dt = data table # tt = thing table rt, account_tt, content_cls_tt, dt = type.rel_table cols = [ sa.func.count(rt.c.rel_id) ] where = sa.and_(rt.c.thing1_id == self._id, rt.c.name == '-1') query = sa.select(cols, where) downvotes = query.execute().scalar() g.cache.set(cache_key, downvotes) return downvotes
def get_cached_downvotes(content_cls): kind = content_cls.__name__.lower() cache_key = self.downvote_cache_key(kind) downvotes = g.cache.get(cache_key) if downvotes is None: vote_cls = Vote.rel(Account, content_cls) # Get a count of content_cls downvotes type = tdb.rel_types_id[vote_cls._type_id] # rt = rel table # dt = data table # tt = thing table rt, account_tt, content_cls_tt, dt = type.rel_table cols = [sa.func.count(rt.c.rel_id)] where = sa.and_(rt.c.thing1_id == self._id, rt.c.name == '-1') query = sa.select(cols, where) downvotes = query.execute().scalar() g.cache.set(cache_key, downvotes) return downvotes