Esempio n. 1
0
    def archive(self):
        """
        Archive the link

        Link get archived to save some memory in redis/db by disallowing voting and commenting on old links
        Upon archiving of the link all votes get deleted and only the final score is kept
        Same thing happens with the votes on comments of this link - votes get deleted and only final score is kept
        """

        # delete link votes from DB
        LinkVote.where("link_id", self.id).delete()
        # delete cached link votes
        link_upvotes_key, link_downvotes_key = LinkVote.set_keys(self.id)
        cache.delete(link_upvotes_key)
        cache.delete(link_downvotes_key)

        # delete comment votes
        for comment in Comment.where("link_id", self.id):
            # delete cached comment votes
            comment_upvotes_key, comment_downvotes_key = CommentVote.set_keys(
                comment.id)
            cache.delete(comment_upvotes_key)
            cache.delete(comment_downvotes_key)
            # delete comment votes from DB
            CommentVote.where("comment_id", comment.id).delete()

        # update self
        with self.get_read_modify_write_lock():
            self.archived = True
            self.update_with_cache()
Esempio n. 2
0
    def votes(self):
        """
        Get link votes
        :return:
        """
        from news.models.vote import LinkVote

        return LinkVote.where("link_id", self.id).get()