Skip to content
Snippets Groups Projects
Commit f7d5c927 authored by roadscape's avatar roadscape
Browse files

force child recount when child node is deleted, fix #208

parent 0b237262
No related branches found
No related tags found
No related merge requests found
...@@ -156,6 +156,11 @@ class Posts: ...@@ -156,6 +156,11 @@ class Posts:
CachedPost.delete(pid, op['author'], op['permlink']) CachedPost.delete(pid, op['author'], op['permlink'])
if depth == 0: if depth == 0:
FeedCache.delete(pid) FeedCache.delete(pid)
else:
# force parent child recount when child is deleted
prnt = cls._get_parent_by_child_id(pid)
CachedPost.recount(prnt['author'], prnt['permlink'], prnt['id'])
@classmethod @classmethod
def update(cls, op, date, pid): def update(cls, op, date, pid):
...@@ -168,6 +173,16 @@ class Posts: ...@@ -168,6 +173,16 @@ class Posts:
if not DbState.is_initial_sync(): if not DbState.is_initial_sync():
CachedPost.update(op['author'], op['permlink'], pid) CachedPost.update(op['author'], op['permlink'], pid)
@classmethod
def _get_parent_by_child_id(cls, child_id):
"""Get parent's `id`, `author`, `permlink` by child id."""
sql = """SELECT id, author, permlink FROM hive_posts
WHERE id = (SELECT parent_id FROM hive_posts
WHERE id = :child_id)"""
result = DB.query_row(sql, child_id=child_id)
assert result, "parent of %d not found" % child_id
return result
@classmethod @classmethod
def _insert_feed_cache(cls, post): def _insert_feed_cache(cls, post):
"""Insert the new post into feed cache if it's not a comment.""" """Insert the new post into feed cache if it's not a comment."""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment