Skip to content
Snippets Groups Projects

Escape characters in user names provided in follow_op

Merged Dariusz Kędzierski requested to merge dk-follow-name-escaping into develop
Files
6
+ 9
8
@@ -10,6 +10,7 @@ from hive.utils.misc import chunks
@@ -10,6 +10,7 @@ from hive.utils.misc import chunks
from hive.indexer.accounts import Accounts
from hive.indexer.accounts import Accounts
from hive.indexer.db_adapter_holder import DbAdapterHolder
from hive.indexer.db_adapter_holder import DbAdapterHolder
 
from hive.utils.normalize import escape_characters
log = logging.getLogger(__name__)
log = logging.getLogger(__name__)
@@ -124,8 +125,8 @@ class Follow(DbAdapterHolder):
@@ -124,8 +125,8 @@ class Follow(DbAdapterHolder):
if non_existent_names:
if non_existent_names:
log.warning("Follow op validation, following names does not exists in database: {}".format(non_existent_names))
log.warning("Follow op validation, following names does not exists in database: {}".format(non_existent_names))
return dict(flr=op['follower'],
return dict(flr=escape_characters(op['follower']),
flg=op['following'],
flg=[escape_characters(following) for following in op['following']],
state=defs[what],
state=defs[what],
at=date)
at=date)
@@ -226,7 +227,7 @@ class Follow(DbAdapterHolder):
@@ -226,7 +227,7 @@ class Follow(DbAdapterHolder):
cls.beginTx()
cls.beginTx()
for _, follow_item in cls.follow_items_to_flush.items():
for _, follow_item in cls.follow_items_to_flush.items():
if count < limit:
if count < limit:
values.append("({}, '{}', '{}', '{}'::timestamp, {}, {}, {}, {}, {})".format(follow_item['idx'],
values.append("({}, {}, {}, '{}'::timestamp, {}, {}, {}, {}, {})".format(follow_item['idx'],
follow_item['flr'],
follow_item['flr'],
follow_item['flg'],
follow_item['flg'],
follow_item['at'],
follow_item['at'],
@@ -241,7 +242,7 @@ class Follow(DbAdapterHolder):
@@ -241,7 +242,7 @@ class Follow(DbAdapterHolder):
query += sql_postfix
query += sql_postfix
cls.db.query(query)
cls.db.query(query)
values.clear()
values.clear()
values.append("({}, '{}', '{}', '{}'::timestamp, {}, {}, {}, {}, {})".format(follow_item['idx'],
values.append("({}, {}, {}, '{}'::timestamp, {}, {}, {}, {}, {})".format(follow_item['idx'],
follow_item['flr'],
follow_item['flr'],
follow_item['flg'],
follow_item['flg'],
follow_item['at'],
follow_item['at'],
@@ -269,7 +270,7 @@ class Follow(DbAdapterHolder):
@@ -269,7 +270,7 @@ class Follow(DbAdapterHolder):
for state, update_flush_items in cls.follow_update_items_to_flush.items():
for state, update_flush_items in cls.follow_update_items_to_flush.items():
for chunk in chunks(update_flush_items, 1000):
for chunk in chunks(update_flush_items, 1000):
sql = None
sql = None
query_values = ','.join(["('{}')".format(account) for account in chunk])
query_values = ','.join(["({})".format(account) for account in chunk])
# [DK] probaly not a bad idea to move that logic to SQL function
# [DK] probaly not a bad idea to move that logic to SQL function
if state == 9:
if state == 9:
#reset blacklists for follower
#reset blacklists for follower
@@ -360,7 +361,7 @@ class Follow(DbAdapterHolder):
@@ -360,7 +361,7 @@ class Follow(DbAdapterHolder):
UPDATE
UPDATE
hive_follows hf
hive_follows hf
SET
SET
hf.follow_blacklists = true
follow_blacklists = true
FROM
FROM
(
(
SELECT
SELECT
@@ -481,7 +482,7 @@ class Follow(DbAdapterHolder):
@@ -481,7 +482,7 @@ class Follow(DbAdapterHolder):
for col, deltas in cls._delta.items():
for col, deltas in cls._delta.items():
for delta, names in _flip_dict(deltas).items():
for delta, names in _flip_dict(deltas).items():
updated += len(names)
updated += len(names)
query_values = ','.join(["('{}')".format(account) for account in names])
query_values = ','.join(["({})".format(account) for account in names])
sql = """
sql = """
UPDATE
UPDATE
hive_accounts ha
hive_accounts ha
@@ -518,7 +519,7 @@ class Follow(DbAdapterHolder):
@@ -518,7 +519,7 @@ class Follow(DbAdapterHolder):
"""
"""
names = set([*cls._delta[FOLLOWERS].keys(),
names = set([*cls._delta[FOLLOWERS].keys(),
*cls._delta[FOLLOWING].keys()])
*cls._delta[FOLLOWING].keys()])
query_values = ','.join(["('{}')".format(account) for account in names])
query_values = ','.join(["({})".format(account) for account in names])
sql = """
sql = """
UPDATE
UPDATE
hive_accounts ha
hive_accounts ha
Loading