From ceecb3ca51407c555806c8c22973fba33cb31c03 Mon Sep 17 00:00:00 2001 From: Logan Hanks Date: Fri, 26 Oct 2012 14:03:18 -0700 Subject: [PATCH] Fix various comment deletion bugs in comment trees. --- r2/r2/lib/comment_tree.py | 6 +++--- r2/r2/models/comment_tree.py | 13 +++++++++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/r2/r2/lib/comment_tree.py b/r2/r2/lib/comment_tree.py index 46ab58361..76d41398a 100755 --- a/r2/r2/lib/comment_tree.py +++ b/r2/r2/lib/comment_tree.py @@ -91,10 +91,10 @@ def update_comment_votes(comments, write_consistency_level = None): write_consistency_level = write_consistency_level) def delete_comment(comment): - with CommentTree.mutation_context(comment.link_id): - link = Link._byID(comment.link_id, data=True) + link = Link._byID(comment.link_id, data=True) + with CommentTree.mutation_context(link): cache = get_comment_tree(link) - cache.delete_comment(comment) + cache.delete_comment(comment, link) from r2.lib.db.queries import changed changed(link) diff --git a/r2/r2/models/comment_tree.py b/r2/r2/models/comment_tree.py index a45353246..06d7b1add 100644 --- a/r2/r2/models/comment_tree.py +++ b/r2/r2/models/comment_tree.py @@ -248,9 +248,14 @@ class CommentTreeStorageV2(CommentTreeStorageBase): @tdb_cassandra.will_write def delete_comment(cls, tree, comment): CommentTreeStorageBase.delete_comment(tree, comment) + pids = [int(pid_str, 36) if pid_str else -1 + for pid_str in comment.parents.split(':')] + pids.append(comment._id) + updates = {} + for d, (pid, cid) in enumerate(zip(pids, pids[1:])): + updates[(d, pid, cid)] = -1 with batch.Mutator(g.cassandra_pools[cls._connection_pool]) as m: - m.insert(cls._cf, cls._key(tree.link_id), - dict((c.parents + ':' + c._id36), '0')) + m.insert(cls._cf, cls._key(tree.link_id), updates) @classmethod @tdb_cassandra.will_write @@ -392,8 +397,8 @@ class CommentTree: def add_comment(self, comment): return self.add_comments([comment]) - def delete_comment(self, comment): - impl = cls.IMPLEMENTATIONS[link.comment_tree_version] + def delete_comment(self, comment, link): + impl = self.IMPLEMENTATIONS[link.comment_tree_version] impl.delete_comment(self, comment) self.link._incr('num_comments', -1)