diff --git a/schema/comments_ddl.sql b/schema/comments_ddl.sql index eb8e1e7..ab81e85 100644 --- a/schema/comments_ddl.sql +++ b/schema/comments_ddl.sql @@ -38,8 +38,9 @@ CREATE TABLE IF NOT EXISTS CHANNEL( -- DROP INDEX IF EXISTS COMMENT_CLAIM_INDEX; CREATE INDEX IF NOT EXISTS CLAIM_COMMENT_INDEX ON COMMENT (LbryClaimId, CommentId); -CREATE INDEX IF NOT EXISTS CHANNEL_COMMENT_INDEX ON COMMENT (ChannelId, CommentId); - +DROP INDEX CHANNEL_COMMENT_INDEX; +CREATE INDEX IF NOT EXISTS CHANNEL_COMMENT_INDEX ON COMMENT(ChannelId, CommentId) +; -- VIEWS DROP VIEW IF EXISTS COMMENTS_ON_CLAIMS; diff --git a/src/database.py b/src/database.py index 6753e8f..9bbbd79 100644 --- a/src/database.py +++ b/src/database.py @@ -170,14 +170,11 @@ def insert_channel(conn: sqlite3.Connection, channel_name: str, channel_id: str) ) -def get_channel_from_comment_id(conn: sqlite3.Connection, comment_id: str): +def get_channel_id_from_comment_id(conn: sqlite3.Connection, comment_id: str): with conn: channel = conn.execute(""" - SELECT CHN.ClaimId AS channel_id, CHN.Name AS channel_name - FROM CHANNEL AS CHN, COMMENT AS CMT - WHERE CHN.ClaimId = CMT.ChannelId AND CMT.CommentId = ? - LIMIT 1 - """, (comment_id,) + SELECT channel_id, channel_name FROM COMMENTS_ON_CLAIMS WHERE comment_id = ? + """, (comment_id,) ).fetchone() return dict(channel) if channel else dict() diff --git a/src/handles.py b/src/handles.py index f981f69..4652d9d 100644 --- a/src/handles.py +++ b/src/handles.py @@ -9,7 +9,7 @@ from asyncio import coroutine from misc import clean_input_params from src.database import get_claim_comments from src.database import get_comments_by_id, get_comment_ids -from src.database import get_channel_from_comment_id +from src.database import get_channel_id_from_comment_id from src.database import obtain_connection from src.database import delete_comment_by_id from src.writes import create_comment_or_error @@ -26,7 +26,7 @@ def ping(*args): def handle_get_channel_from_comment_id(app, kwargs: dict): with obtain_connection(app['db_path']) as conn: - return get_channel_from_comment_id(conn, **kwargs) + return get_channel_id_from_comment_id(conn, **kwargs) def handle_get_comment_ids(app, kwargs):