From 7916d8b7ff12a749167117eadc0793d32d2276ce Mon Sep 17 00:00:00 2001 From: Oleg Silkin Date: Mon, 6 Jan 2020 23:03:59 -0500 Subject: [PATCH 1/2] All comment returning methods now include `claim_id` --- src/database/queries.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/database/queries.py b/src/database/queries.py index 16e6f0b..03815aa 100644 --- a/src/database/queries.py +++ b/src/database/queries.py @@ -12,14 +12,8 @@ from src.database.schema import CREATE_TABLES_QUERY logger = logging.getLogger(__name__) SELECT_COMMENTS_ON_CLAIMS = """ - SELECT comment, comment_id, channel_name, channel_id, channel_url, - timestamp, signature, signing_ts, parent_id, is_hidden - FROM COMMENTS_ON_CLAIMS -""" - -SELECT_COMMENTS_ON_CLAIMS_CLAIMID = """ - SELECT comment, comment_id, claim_id, channel_name, channel_id, channel_url, - timestamp, signature, signing_ts, parent_id, is_hidden + SELECT comment, comment_id, claim_id, timestamp, is_hidden, parent_id, + channel_name, channel_id, channel_url, signature, signing_ts FROM COMMENTS_ON_CLAIMS """ @@ -164,7 +158,7 @@ def insert_reply(conn: sqlite3.Connection, comment: str, parent_id: str, def get_comment_or_none(conn: sqlite3.Connection, comment_id: str) -> dict: with conn: - curry = conn.execute(SELECT_COMMENTS_ON_CLAIMS_CLAIMID + "WHERE comment_id = ?", (comment_id,)) + curry = conn.execute(SELECT_COMMENTS_ON_CLAIMS + "WHERE comment_id = ?", (comment_id,)) thing = curry.fetchone() return clean(dict(thing)) if thing else None @@ -199,7 +193,7 @@ def get_comments_by_id(conn, comment_ids: typing.Union[list, tuple]) -> typing.U placeholders = ', '.join('?' for _ in comment_ids) with conn: return [clean(dict(row)) for row in conn.execute( - SELECT_COMMENTS_ON_CLAIMS_CLAIMID + f'WHERE comment_id IN ({placeholders})', + SELECT_COMMENTS_ON_CLAIMS + f'WHERE comment_id IN ({placeholders})', tuple(comment_ids) )] From 25eb4f9acdcfedc80259f53bf92f22225d35cdac Mon Sep 17 00:00:00 2001 From: Oleg Silkin Date: Mon, 6 Jan 2020 23:16:46 -0500 Subject: [PATCH 2/2] Prevents claim resolve error from disrupting entire hide operation --- src/database/writes.py | 6 ++++-- src/server/misc.py | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/database/writes.py b/src/database/writes.py index e724521..0e7b17d 100644 --- a/src/database/writes.py +++ b/src/database/writes.py @@ -88,7 +88,10 @@ async def hide_comments(app, pieces: list) -> list: for p in pieces: claim_id = comment_cids[p['comment_id']] if claim_id not in claims: - claims[claim_id] = await get_claim_from_id(app, claim_id, no_totals=True) + claim = await get_claim_from_id(app, claim_id) + if claim: + claims[claim_id] = claim + channel = claims[claim_id].get('signing_channel') if validate_signature_from_claim(channel, p['signature'], p['signing_ts'], p['comment_id']): comments_to_hide.append(p) @@ -100,7 +103,6 @@ async def hide_comments(app, pieces: list) -> list: app, 'UPDATE', db.get_comments_by_id(app['reader'], comment_ids) ) ) - await job.wait() return comment_ids diff --git a/src/server/misc.py b/src/server/misc.py index 593e61a..4f620e6 100644 --- a/src/server/misc.py +++ b/src/server/misc.py @@ -8,7 +8,10 @@ ID_LIST = {'claim_id', 'parent_id', 'comment_id', 'channel_id'} async def get_claim_from_id(app, claim_id, **kwargs): - return (await request_lbrynet(app, 'claim_search', claim_id=claim_id, **kwargs))['items'][0] + try: + return (await request_lbrynet(app, 'claim_search', claim_id=claim_id, **kwargs))['items'][0] + except IndexError: + return def clean_input_params(kwargs: dict):