Skip to content
Snippets Groups Projects
Commit 91de1219 authored by Mariusz Trela's avatar Mariusz Trela
Browse files

Final fixes in SQL functions: `delete_reblog_feed_cache`, `delete_hive_post`

parent df916d08
No related branches found
No related tags found
No related merge requests found
DROP FUNCTION IF EXISTS delete_reblog_feed_cache(character varying,character varying,character varying, BOOLEAN)
DROP FUNCTION IF EXISTS delete_reblog_feed_cache(character varying,character varying,character varying)
;
CREATE OR REPLACE FUNCTION delete_reblog_feed_cache(
in _author hive_accounts.name%TYPE,
in _permlink hive_permlink_data.permlink%TYPE,
in _account hive_accounts.name%TYPE,
in _delete_feed_cache BOOLEAN)
in _account hive_accounts.name%TYPE)
RETURNS INTEGER
LANGUAGE plpgsql
AS
......@@ -26,10 +25,8 @@ BEGIN
DELETE FROM hive_reblogs
WHERE blogger_id = __account_id AND post_id = __post_id;
IF _delete_feed_cache THEN
DELETE FROM hive_feed_cache
WHERE account_id = __account_id AND post_id = __post_id;
END IF;
DELETE FROM hive_feed_cache
WHERE account_id = __account_id AND post_id = __post_id;
RETURN 1;
END
......
......@@ -144,13 +144,12 @@ END
$function$
;
DROP FUNCTION if exists delete_hive_post(character varying,character varying,character varying, integer, BOOLEAN)
DROP FUNCTION if exists delete_hive_post(character varying,character varying,character varying, integer)
;
CREATE OR REPLACE FUNCTION delete_hive_post(
in _author hive_accounts.name%TYPE,
in _permlink hive_permlink_data.permlink%TYPE,
in _block_num hive_blocks.num%TYPE,
in _delete_feed_cache BOOLEAN)
in _block_num hive_blocks.num%TYPE)
RETURNS VOID
LANGUAGE plpgsql
AS
......@@ -180,10 +179,8 @@ BEGIN
DELETE FROM hive_reblogs
WHERE post_id = __post_id;
IF _delete_feed_cache THEN
DELETE FROM hive_feed_cache
WHERE post_id = __post_id;
END IF;
DELETE FROM hive_feed_cache
WHERE post_id = __post_id;
END
$function$
......
......@@ -390,11 +390,8 @@ class Posts(DbAdapterHolder):
@classmethod
def delete(cls, op):
"""Marks a post record as being deleted."""
delete_feed_cache = not DbState.is_initial_sync()
sql = "SELECT delete_hive_post((:author)::varchar, (:permlink)::varchar, (:block_num)::int, (:delete_feed_cache)::BOOLEAN );"
DB.query_no_return(sql, author=op['author'], permlink = op['permlink'], block_num=op['block_num'], delete_feed_cache=delete_feed_cache)
sql = "SELECT delete_hive_post((:author)::varchar, (:permlink)::varchar, (:block_num)::int );"
DB.query_no_return(sql, author=op['author'], permlink = op['permlink'], block_num=op['block_num'])
@classmethod
def _verify_post_against_community(cls, op, community_id, is_valid, is_muted):
......
......@@ -60,11 +60,8 @@ class Reblog(DbAdapterHolder):
def delete(cls, author, permlink, account ):
"""Remove a reblog from hive_reblogs + feed from hive_feed_cache.
"""
delete_feed_cache = not DbState.is_initial_sync()
sql = "SELECT delete_reblog_feed_cache( (:author)::VARCHAR, (:permlink)::VARCHAR, (:account)::VARCHAR, (:delete_feed_cache)::BOOLEAN );"
status = DB.query_col(sql, author=author, permlink=permlink, account=account, delete_feed_cache=delete_feed_cache);
log.info( "mario: author: %s, permlink: %s, account: %s status: %s", author, permlink, account, status )
sql = "SELECT delete_reblog_feed_cache( (:author)::VARCHAR, (:permlink)::VARCHAR, (:account)::VARCHAR );"
status = DB.query_col(sql, author=author, permlink=permlink, account=account);
assert status is not None
if status == 0:
log.debug("reblog: post not found: %s/%s", author, permlink)
......@@ -103,9 +100,9 @@ class Reblog(DbAdapterHolder):
continue
reblog_item = v['op']
if count < limit:
values.append("('{}', '{}', '{}', '{}'::timestamp, {})".format(reblog_item['account'],
reblog_item['author'],
reblog_item['permlink'],
values.append("({}, {}, {}, '{}'::timestamp, {})".format(escape_characters(reblog_item['account']),
escape_characters(reblog_item['author']),
escape_characters(reblog_item['permlink']),
reblog_item['block_date'],
reblog_item['block_num']))
count = count + 1
......@@ -114,9 +111,9 @@ class Reblog(DbAdapterHolder):
query = sql_prefix.format(values_str, values_str)
cls.db.query(query)
values.clear()
values.append("('{}', '{}', '{}', '{}'::timestamp, {})".format(reblog_item['account'],
reblog_item['author'],
reblog_item['permlink'],
values.append("({}, {}, {}, '{}'::timestamp, {})".format(escape_characters(reblog_item['account']),
escape_characters(reblog_item['author']),
escape_characters(reblog_item['permlink']),
reblog_item['block_date'],
reblog_item['block_num']))
count = 1
......
......@@ -12,6 +12,17 @@
"ref_block_prefix": 0,
"expiration": "2020-03-23T12:08:00",
"operations": [
{
"type": "custom_json_operation",
"value": {
"required_auths": [],
"required_posting_auths": [
"funny"
],
"id": "follow",
"json": "[\"reblog\",{\"account\":\"funny\",\"author\":\"steemit\",\"permlink\":\"fi\nrst'%@post\"}]"
}
},
{
"type": "custom_json_operation",
"value": {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment