mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-04-05 03:00:15 -04:00
Fix bug where top-level comments are added to v2 tree twice.
This commit is contained in:
@@ -238,13 +238,13 @@ class CommentTreeStorageV2(CommentTreeStorageBase):
|
||||
# make sure all comments have parents attribute filled in
|
||||
parents = {c._id: c.parent_id for c in comments}
|
||||
for c in comments:
|
||||
if not c.parents:
|
||||
if c.parent_id and c.parents is None:
|
||||
path = []
|
||||
pid = c.parent_id
|
||||
while pid:
|
||||
path.insert(0, pid)
|
||||
pid = parents[pid]
|
||||
c.parents = ':' + ':'.join(utils.to36(i) for i in path)
|
||||
c.parents = ':'.join(utils.to36(i) for i in path)
|
||||
c._commit()
|
||||
|
||||
return cls.add_comments(tree, comments)
|
||||
@@ -256,8 +256,7 @@ class CommentTreeStorageV2(CommentTreeStorageBase):
|
||||
g.log.debug('building updates dict')
|
||||
updates = {}
|
||||
for c in comments:
|
||||
pids = [int(pid_str, 36) if pid_str else -1
|
||||
for pid_str in c.parents.split(':')]
|
||||
pids = c.parent_path()
|
||||
pids.append(c._id)
|
||||
for d, (pid, cid) in enumerate(zip(pids, pids[1:])):
|
||||
k = (d, pid, cid)
|
||||
@@ -281,8 +280,7 @@ 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 = comment.parent_path()
|
||||
pids.append(comment._id)
|
||||
updates = {}
|
||||
for d, (pid, cid) in enumerate(zip(pids, pids[1:])):
|
||||
|
||||
@@ -696,12 +696,16 @@ class Comment(Thing, Printable):
|
||||
|
||||
kw = {}
|
||||
if link.comment_tree_version > 1:
|
||||
# for top-level comments, parents is an empty string
|
||||
# for all others, it looks like "<id36>:<id36>:...".
|
||||
if parent:
|
||||
if not parent.parents:
|
||||
parent._fill_in_parents()
|
||||
kw['parents'] = parent.parents + ':' + parent._id36
|
||||
else:
|
||||
kw['parents'] = ':'
|
||||
if parent.parent_id:
|
||||
if parent.parents is None:
|
||||
parent._fill_in_parents()
|
||||
kw['parents'] = parent.parents + ':' + parent._id36
|
||||
else:
|
||||
kw['parents'] = parent._id36
|
||||
|
||||
c = Comment(_ups=1,
|
||||
body=body,
|
||||
link_id=link._id,
|
||||
@@ -797,15 +801,40 @@ class Comment(Thing, Printable):
|
||||
|
||||
def _fill_in_parents(self):
|
||||
if not self.parent_id:
|
||||
self.parents = ':'
|
||||
self.parents = ''
|
||||
self._commit()
|
||||
return
|
||||
parent = Comment._byID(self.parent_id)
|
||||
if not parent.parents:
|
||||
parent._fill_in_parents()
|
||||
self.parents = parent.parents + ':' + parent._id36
|
||||
if parent.parent_id:
|
||||
if parent.parents is None:
|
||||
parent._fill_in_parents()
|
||||
self.parents = parent.parents + ':' + parent._id36
|
||||
else:
|
||||
self.parents = parent._id36
|
||||
self._commit()
|
||||
|
||||
def parent_path(self):
|
||||
"""Returns path of comment in tree as list of comment ids.
|
||||
|
||||
The returned list will always begin with -1, followed by comment ids in
|
||||
path order. The return value for top-level comments will always be [-1].
|
||||
"""
|
||||
if self.parent_id and self.parents is None:
|
||||
self._fill_in_parents()
|
||||
|
||||
if self.parents is None:
|
||||
return [-1]
|
||||
|
||||
# eliminate any leading colons from the path and parse
|
||||
pids = [long(pid_str, 36) if pid_str else -1
|
||||
for pid_str in self.parents.lstrip(':').split(':')]
|
||||
|
||||
# ensure path starts with -1
|
||||
if pids[0] != -1:
|
||||
pids.insert(0, -1)
|
||||
|
||||
return pids
|
||||
|
||||
@classmethod
|
||||
def add_props(cls, user, wrapped):
|
||||
from r2.lib.template_helpers import add_attr, get_domain
|
||||
|
||||
Reference in New Issue
Block a user