Skip to content
Snippets Groups Projects
Commit 3b8dd49d authored by Dariusz Kędzierski's avatar Dariusz Kędzierski
Browse files

Fix in find root

parent c98d5dca
No related branches found
No related tags found
5 merge requests!456Release candidate v1 24,!230Setup monitoring with pghero,!135Enable postgres monitoring on CI server,!16Dk issue 3 concurrent block query rebase,!15Dk issue 3 concurrent block query
...@@ -35,18 +35,20 @@ class Posts: ...@@ -35,18 +35,20 @@ class Posts:
@classmethod @classmethod
def find_root(cls, author, permlink): def find_root(cls, author, permlink):
""" Find root for post """ """ Find root for post """
sql = """WITH parent AS print("A: ", author, "P: ", permlink)
sql = """WITH RECURSIVE parent AS
( (
SELECT id, parent_id, 1 AS [level] from hive_posts WHERE id = (SELECT hp.id SELECT id, parent_id, 1 AS level from hive_posts WHERE id = (SELECT hp.id
FROM hive_posts hp FROM hive_posts hp
LEFT JOIN hive_accounts ha_a ON ha_a.id = hp.author_id LEFT JOIN hive_accounts ha_a ON ha_a.id = hp.author_id
LEFT JOIN hive_permlink_data hpd_p ON hpd_p.id = hp.permlink_id LEFT JOIN hive_permlink_data hpd_p ON hpd_p.id = hp.permlink_id
WHERE ha_a.name = :a AND hpd_p.permlink = :p) WHERE ha_a.name = :a AND hpd_p.permlink = :p)
UNION ALL UNION ALL
SELECT t.id, t.parent_id, [level] + 1 FROM parent SELECT t.id, t.parent_id, level + 1 FROM parent
INNER JOIN hive_posts t ON t.id = parent.parent_id INNER JOIN hive_posts t ON t.id = parent.parent_id
) )
SELECT TOP 1 id FROM parent ORDER BY [level] DESC""" SELECT id FROM parent ORDER BY level DESC LIMIT 1"""
_id = DB.query_one(sql, a=author, p=permlink) _id = DB.query_one(sql, a=author, p=permlink)
return _id return _id
...@@ -187,6 +189,7 @@ class Posts: ...@@ -187,6 +189,7 @@ class Posts:
@classmethod @classmethod
def insert(cls, hived, op, date): def insert(cls, hived, op, date):
"""Inserts new post records.""" """Inserts new post records."""
print("New Post")
# inserting new post # inserting new post
# * Check for permlink, parent_permlink, root_permlink # * Check for permlink, parent_permlink, root_permlink
...@@ -316,6 +319,7 @@ class Posts: ...@@ -316,6 +319,7 @@ class Posts:
@classmethod @classmethod
def undelete(cls, op, date, pid): def undelete(cls, op, date, pid):
"""Re-allocates an existing record flagged as deleted.""" """Re-allocates an existing record flagged as deleted."""
print("Undelete")
# add category to category table # add category to category table
if 'category' in op: if 'category' in op:
sql = """ sql = """
...@@ -342,6 +346,8 @@ class Posts: ...@@ -342,6 +346,8 @@ class Posts:
@classmethod @classmethod
def delete(cls, op): def delete(cls, op):
"""Marks a post record as being deleted.""" """Marks a post record as being deleted."""
print("Delete post")
pid, depth = cls.get_id_and_depth(op['author'], op['permlink']) pid, depth = cls.get_id_and_depth(op['author'], op['permlink'])
DB.query("UPDATE hive_posts SET is_deleted = '1' WHERE id = :id", id=pid) DB.query("UPDATE hive_posts SET is_deleted = '1' WHERE id = :id", id=pid)
...@@ -362,6 +368,7 @@ class Posts: ...@@ -362,6 +368,7 @@ class Posts:
Here we could also build content diffs, but for now just used Here we could also build content diffs, but for now just used
a signal to update cache record. a signal to update cache record.
""" """
print("Update post")
# pylint: disable=unused-argument # pylint: disable=unused-argument
# add category to category table # add category to category table
...@@ -518,7 +525,7 @@ class Posts: ...@@ -518,7 +525,7 @@ class Posts:
if not is_valid: error = 'replying to invalid post' if not is_valid: error = 'replying to invalid post'
elif is_muted: error = 'replying to muted post' elif is_muted: error = 'replying to muted post'
#find root comment #find root comment
root_id = cls.find_root(op['author'], op['permlink']) root_id = cls.find_root(op['parent_author'], op['parent_permlink'])
sql = """ sql = """
SELECT SELECT
ha_a.name as author, hpd_p.permlink as permlink ha_a.name as author, hpd_p.permlink as permlink
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment