Skip to content
Snippets Groups Projects
Commit 607d1048 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
This commit is part of merge request !400. Comments created here will be created in the context of that merge request.
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):
......
......@@ -34,9 +34,9 @@ class Reblog(DbAdapterHolder):
_delete = True if ('delete' in op and op['delete'] == 'delete') else False
return dict(author = op['author'],
permlink = op['permlink'],
account = op['account'],
return dict(author = escape_characters(op['author']),
permlink = escape_characters(op['permlink']),
account = escape_characters(op['account']),
block_date = block_date,
block_num = block_num,
delete = _delete )
......@@ -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)
......
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