Activates Comment Deletion functionality + adds & fixes a ton of stuff #3
5 changed files with 43 additions and 33 deletions
|
@ -1,4 +1,3 @@
|
|||
|
||||
PRAGMA FOREIGN_KEYS = ON;
|
||||
|
||||
-- tables
|
||||
|
@ -6,7 +5,8 @@ PRAGMA FOREIGN_KEYS = ON;
|
|||
-- DROP TABLE IF EXISTS CHANNEL;
|
||||
|
||||
-- DROP TABLE IF EXISTS COMMENT;
|
||||
CREATE TABLE IF NOT EXISTS COMMENT (
|
||||
CREATE TABLE IF NOT EXISTS COMMENT
|
||||
(
|
||||
CommentId TEXT NOT NULL,
|
||||
LbryClaimId TEXT NOT NULL,
|
||||
ChannelId TEXT DEFAULT NULL,
|
||||
|
@ -17,16 +17,17 @@ CREATE TABLE IF NOT EXISTS COMMENT (
|
|||
SigningTs TEXT DEFAULT NULL,
|
||||
CONSTRAINT COMMENT_PRIMARY_KEY PRIMARY KEY (CommentId) ON CONFLICT IGNORE,
|
||||
CONSTRAINT COMMENT_SIGNATURE_SK UNIQUE (Signature) ON CONFLICT ABORT,
|
||||
CONSTRAINT COMMENT_CHANNEL_FK FOREIGN KEY (ChannelId) REFERENCES CHANNEL(ClaimId)
|
||||
CONSTRAINT COMMENT_CHANNEL_FK FOREIGN KEY (ChannelId) REFERENCES CHANNEL (ClaimId)
|
||||
ON DELETE NO ACTION ON UPDATE NO ACTION,
|
||||
CONSTRAINT COMMENT_PARENT_FK FOREIGN KEY (ParentId) REFERENCES COMMENT(CommentId)
|
||||
CONSTRAINT COMMENT_PARENT_FK FOREIGN KEY (ParentId) REFERENCES COMMENT (CommentId)
|
||||
ON UPDATE CASCADE ON DELETE NO ACTION -- setting null implies comment is top level
|
||||
);
|
||||
|
||||
-- ALTER TABLE COMMENT ADD COLUMN SigningTs TEXT DEFAULT NULL;
|
||||
|
||||
-- DROP TABLE IF EXISTS CHANNEL;
|
||||
CREATE TABLE IF NOT EXISTS CHANNEL(
|
||||
CREATE TABLE IF NOT EXISTS CHANNEL
|
||||
(
|
||||
ClaimId TEXT NOT NULL,
|
||||
Name TEXT NOT NULL,
|
||||
CONSTRAINT CHANNEL_PK PRIMARY KEY (ClaimId)
|
||||
|
@ -38,26 +39,37 @@ 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);
|
||||
CREATE INDEX IF NOT EXISTS CHANNEL_COMMENT_INDEX ON COMMENT (ChannelId, CommentId);
|
||||
|
||||
-- VIEWS
|
||||
DROP VIEW IF EXISTS COMMENTS_ON_CLAIMS;
|
||||
CREATE VIEW IF NOT EXISTS COMMENTS_ON_CLAIMS (comment_id, claim_id, timestamp, channel_name, channel_id, channel_url, signature, signing_ts, parent_id, comment) AS
|
||||
SELECT C.CommentId, C.LbryClaimId, C.Timestamp, CHAN.Name, CHAN.ClaimId, 'lbry://' || CHAN.Name || '#' || CHAN.ClaimId, C.Signature, C.SigningTs, C.ParentId, C.Body
|
||||
FROM COMMENT AS C
|
||||
CREATE VIEW IF NOT EXISTS COMMENTS_ON_CLAIMS (comment_id, claim_id, timestamp, channel_name, channel_id, channel_url,
|
||||
signature, signing_ts, parent_id, comment) AS
|
||||
SELECT C.CommentId,
|
||||
C.LbryClaimId,
|
||||
C.Timestamp,
|
||||
CHAN.Name,
|
||||
CHAN.ClaimId,
|
||||
'lbry://' || CHAN.Name || '#' || CHAN.ClaimId,
|
||||
C.Signature,
|
||||
C.SigningTs,
|
||||
C.ParentId,
|
||||
C.Body
|
||||
FROM COMMENT AS C
|
||||
LEFT OUTER JOIN CHANNEL CHAN on C.ChannelId = CHAN.ClaimId
|
||||
ORDER BY C.Timestamp DESC;
|
||||
ORDER BY C.Timestamp DESC;
|
||||
|
||||
|
||||
|
||||
DROP VIEW IF EXISTS COMMENT_REPLIES;
|
||||
CREATE VIEW IF NOT EXISTS COMMENT_REPLIES (Author, CommentBody, ParentAuthor, ParentCommentBody) AS
|
||||
SELECT AUTHOR.Name, OG.Body, PCHAN.Name, PARENT.Body FROM COMMENT AS OG
|
||||
SELECT AUTHOR.Name, OG.Body, PCHAN.Name, PARENT.Body
|
||||
FROM COMMENT AS OG
|
||||
JOIN COMMENT AS PARENT
|
||||
ON OG.ParentId = PARENT.CommentId
|
||||
JOIN CHANNEL AS PCHAN ON PARENT.ChannelId = PCHAN.ClaimId
|
||||
JOIN CHANNEL AS AUTHOR ON OG.ChannelId = AUTHOR.ClaimId
|
||||
ORDER BY OG.Timestamp;
|
||||
ORDER BY OG.Timestamp;
|
||||
|
||||
-- this is the default channel for anyone who wants to publish anonymously
|
||||
-- INSERT INTO CHANNEL
|
||||
|
|
|
@ -17,7 +17,6 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
|
||||
async def setup_db_schema(app):
|
||||
|
||||
if not pathlib.Path(app['db_path']).exists():
|
||||
logger.info('Setting up schema in %s', app['db_path'])
|
||||
setup_database(app['db_path'], app['config']['PATH']['SCHEMA'])
|
||||
|
|
|
@ -31,14 +31,14 @@ def get_claim_comments(conn: sqlite3.Connection, claim_id: str, parent_id: str =
|
|||
FROM COMMENTS_ON_CLAIMS
|
||||
WHERE claim_id = ? AND parent_id IS NULL
|
||||
LIMIT ? OFFSET ? """,
|
||||
(claim_id, page_size, page_size*(page - 1))
|
||||
(claim_id, page_size, page_size * (page - 1))
|
||||
)]
|
||||
count = conn.execute(
|
||||
"""
|
||||
SELECT COUNT(*)
|
||||
FROM COMMENTS_ON_CLAIMS
|
||||
WHERE claim_id = ? AND parent_id IS NULL
|
||||
""", (claim_id, )
|
||||
""", (claim_id,)
|
||||
)
|
||||
elif parent_id is None:
|
||||
results = [clean(dict(row)) for row in conn.execute(
|
||||
|
@ -47,7 +47,7 @@ def get_claim_comments(conn: sqlite3.Connection, claim_id: str, parent_id: str =
|
|||
FROM COMMENTS_ON_CLAIMS
|
||||
WHERE claim_id = ?
|
||||
LIMIT ? OFFSET ? """,
|
||||
(claim_id, page_size, page_size*(page - 1))
|
||||
(claim_id, page_size, page_size * (page - 1))
|
||||
)]
|
||||
count = conn.execute(
|
||||
"""
|
||||
|
@ -63,7 +63,7 @@ def get_claim_comments(conn: sqlite3.Connection, claim_id: str, parent_id: str =
|
|||
FROM COMMENTS_ON_CLAIMS
|
||||
WHERE claim_id = ? AND parent_id = ?
|
||||
LIMIT ? OFFSET ? """,
|
||||
(claim_id, parent_id, page_size, page_size*(page - 1))
|
||||
(claim_id, parent_id, page_size, page_size * (page - 1))
|
||||
)]
|
||||
count = conn.execute(
|
||||
"""
|
||||
|
@ -77,7 +77,7 @@ def get_claim_comments(conn: sqlite3.Connection, claim_id: str, parent_id: str =
|
|||
'items': results,
|
||||
'page': page,
|
||||
'page_size': page_size,
|
||||
'total_pages': math.ceil(count/page_size),
|
||||
'total_pages': math.ceil(count / page_size),
|
||||
'total_items': count
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
import json
|
||||
import pathlib
|
||||
|
||||
|
||||
root_dir = pathlib.Path(__file__).parent.parent
|
||||
config_path = root_dir / 'config' / 'conf.json'
|
||||
|
||||
|
|
Loading…
Reference in a new issue