def flag_topic(tid): key = 'flag:%d:t-%d' % (current_user.id, tid) if cache.get(key): return '', 204 cache.inc(key) TopicStat(tid).flag() return '', 204
def flag_topic_comment(tid, cid): key = 'flag:%d:c-%d' % (current_user.id, cid) if cache.get(key): return '', 204 comment = get_comment_or_404(tid, cid) # here is a concurrency bug, but it doesn't matter comment.flag_count += 1 with db.auto_commit(): db.session.add(comment) # one person, one flag cache.inc(key) return '', 204
def receive_after_insert(mapper, conn, target): cache.inc(target.generate_cache_prefix('count'))