Ejemplo n.º 1
0
def update_sticky_thread_cache():
    threads = RedisList(STICKY_THREAD_CACHE_KEY)
    threads.delete()
    for x in [
            util.dumps((x.comment.id, x.text))
            for x in StickyThread.objects.all()
    ]:
        threads.rpush(x)
Ejemplo n.º 2
0
    def update_scores(self):

        for algo in self.algorithms:
            ranking = algo.fun()
            temp_list = RedisList(gen_temp_key())

            if ranking:
                for comment in ranking:
                    temp_list.rpush(comment.id)

                # Atomically replace the frontpage with the new version.
                temp_list.rename(algo.frontpage.key)
            else:
                # If the ranking is empty, we just delete the frontpage key (the rename will fail)
                algo.frontpage.delete()
Ejemplo n.º 3
0
 def __init__(self, fun):
     self.fun = fun
     self.name = fun.__name__
     self.frontpage = RedisList('frontpage:%s' % self.name)
Ejemplo n.º 4
0
def get_sticky_threads_from_cache():
    """ Returns a list of comment ID / sticky text pairs. """
    threads = RedisList(STICKY_THREAD_CACHE_KEY)
    return [tuple(util.loads(thread)) for thread in threads.lrange(0, -1)]
Ejemplo n.º 5
0
def get_sticky_threads_from_cache():
    """ Returns a list of comment ID / sticky text pairs. """
    threads = RedisList(STICKY_THREAD_CACHE_KEY)
    return [tuple(util.loads(thread)) for thread in threads.lrange(0, -1)]
Ejemplo n.º 6
0
def update_sticky_thread_cache():
    threads = RedisList(STICKY_THREAD_CACHE_KEY)
    threads.delete()
    for x in [util.dumps((x.comment.id, x.text)) for x in StickyThread.objects.all()]:
        threads.rpush(x)