Reformats code
This commit is contained in:
parent
c9996fd658
commit
35c95a0037
5 changed files with 43 additions and 33 deletions
|
@ -17,7 +17,7 @@ def config_logging_from_settings(conf):
|
||||||
"datefmt": conf['LOGGING']['DATEFMT']
|
"datefmt": conf['LOGGING']['DATEFMT']
|
||||||
},
|
},
|
||||||
"aiohttp": {
|
"aiohttp": {
|
||||||
"format": conf['LOGGING']['AIOHTTP_FORMAT'],
|
"format": conf['LOGGING']['AIOHTTP_FORMAT'],
|
||||||
"datefmt": conf['LOGGING']['DATEFMT']
|
"datefmt": conf['LOGGING']['DATEFMT']
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
PRAGMA FOREIGN_KEYS = ON;
|
PRAGMA FOREIGN_KEYS = ON;
|
||||||
|
|
||||||
-- tables
|
-- tables
|
||||||
|
@ -6,29 +5,31 @@ PRAGMA FOREIGN_KEYS = ON;
|
||||||
-- DROP TABLE IF EXISTS CHANNEL;
|
-- DROP TABLE IF EXISTS CHANNEL;
|
||||||
|
|
||||||
-- DROP TABLE IF EXISTS COMMENT;
|
-- DROP TABLE IF EXISTS COMMENT;
|
||||||
CREATE TABLE IF NOT EXISTS COMMENT (
|
CREATE TABLE IF NOT EXISTS COMMENT
|
||||||
|
(
|
||||||
CommentId TEXT NOT NULL,
|
CommentId TEXT NOT NULL,
|
||||||
LbryClaimId TEXT NOT NULL,
|
LbryClaimId TEXT NOT NULL,
|
||||||
ChannelId TEXT DEFAULT NULL,
|
ChannelId TEXT DEFAULT NULL,
|
||||||
Body TEXT NOT NULL,
|
Body TEXT NOT NULL,
|
||||||
ParentId TEXT DEFAULT NULL,
|
ParentId TEXT DEFAULT NULL,
|
||||||
Signature TEXT DEFAULT NULL,
|
Signature TEXT DEFAULT NULL,
|
||||||
Timestamp INTEGER NOT NULL,
|
Timestamp INTEGER NOT NULL,
|
||||||
SigningTs TEXT DEFAULT NULL,
|
SigningTs TEXT DEFAULT NULL,
|
||||||
CONSTRAINT COMMENT_PRIMARY_KEY PRIMARY KEY (CommentId) ON CONFLICT IGNORE,
|
CONSTRAINT COMMENT_PRIMARY_KEY PRIMARY KEY (CommentId) ON CONFLICT IGNORE,
|
||||||
CONSTRAINT COMMENT_SIGNATURE_SK UNIQUE (Signature) ON CONFLICT ABORT,
|
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,
|
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
|
ON UPDATE CASCADE ON DELETE NO ACTION -- setting null implies comment is top level
|
||||||
);
|
);
|
||||||
|
|
||||||
-- ALTER TABLE COMMENT ADD COLUMN SigningTs TEXT DEFAULT NULL;
|
-- ALTER TABLE COMMENT ADD COLUMN SigningTs TEXT DEFAULT NULL;
|
||||||
|
|
||||||
-- DROP TABLE IF EXISTS CHANNEL;
|
-- 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,
|
ClaimId TEXT NOT NULL,
|
||||||
|
Name TEXT NOT NULL,
|
||||||
CONSTRAINT CHANNEL_PK PRIMARY KEY (ClaimId)
|
CONSTRAINT CHANNEL_PK PRIMARY KEY (ClaimId)
|
||||||
ON CONFLICT IGNORE
|
ON CONFLICT IGNORE
|
||||||
);
|
);
|
||||||
|
@ -38,26 +39,37 @@ CREATE TABLE IF NOT EXISTS CHANNEL(
|
||||||
-- DROP INDEX IF EXISTS COMMENT_CLAIM_INDEX;
|
-- DROP INDEX IF EXISTS COMMENT_CLAIM_INDEX;
|
||||||
CREATE INDEX IF NOT EXISTS CLAIM_COMMENT_INDEX ON COMMENT (LbryClaimId, CommentId);
|
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
|
-- VIEWS
|
||||||
DROP VIEW IF EXISTS COMMENTS_ON_CLAIMS;
|
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
|
CREATE VIEW IF NOT EXISTS COMMENTS_ON_CLAIMS (comment_id, claim_id, timestamp, channel_name, channel_id, channel_url,
|
||||||
SELECT C.CommentId, C.LbryClaimId, C.Timestamp, CHAN.Name, CHAN.ClaimId, 'lbry://' || CHAN.Name || '#' || CHAN.ClaimId, C.Signature, C.SigningTs, C.ParentId, C.Body
|
signature, signing_ts, parent_id, comment) AS
|
||||||
FROM COMMENT AS C
|
SELECT C.CommentId,
|
||||||
LEFT OUTER JOIN CHANNEL CHAN on C.ChannelId = CHAN.ClaimId
|
C.LbryClaimId,
|
||||||
ORDER BY C.Timestamp DESC;
|
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;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
DROP VIEW IF EXISTS COMMENT_REPLIES;
|
DROP VIEW IF EXISTS COMMENT_REPLIES;
|
||||||
CREATE VIEW IF NOT EXISTS COMMENT_REPLIES (Author, CommentBody, ParentAuthor, ParentCommentBody) AS
|
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
|
||||||
JOIN COMMENT AS PARENT
|
FROM COMMENT AS OG
|
||||||
ON OG.ParentId = PARENT.CommentId
|
JOIN COMMENT AS PARENT
|
||||||
JOIN CHANNEL AS PCHAN ON PARENT.ChannelId = PCHAN.ClaimId
|
ON OG.ParentId = PARENT.CommentId
|
||||||
JOIN CHANNEL AS AUTHOR ON OG.ChannelId = AUTHOR.ClaimId
|
JOIN CHANNEL AS PCHAN ON PARENT.ChannelId = PCHAN.ClaimId
|
||||||
ORDER BY OG.Timestamp;
|
JOIN CHANNEL AS AUTHOR ON OG.ChannelId = AUTHOR.ClaimId
|
||||||
|
ORDER BY OG.Timestamp;
|
||||||
|
|
||||||
-- this is the default channel for anyone who wants to publish anonymously
|
-- this is the default channel for anyone who wants to publish anonymously
|
||||||
-- INSERT INTO CHANNEL
|
-- INSERT INTO CHANNEL
|
||||||
|
|
|
@ -17,7 +17,6 @@ logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
async def setup_db_schema(app):
|
async def setup_db_schema(app):
|
||||||
|
|
||||||
if not pathlib.Path(app['db_path']).exists():
|
if not pathlib.Path(app['db_path']).exists():
|
||||||
logger.info('Setting up schema in %s', app['db_path'])
|
logger.info('Setting up schema in %s', app['db_path'])
|
||||||
setup_database(app['db_path'], app['config']['PATH']['SCHEMA'])
|
setup_database(app['db_path'], app['config']['PATH']['SCHEMA'])
|
||||||
|
@ -117,4 +116,4 @@ def run_app(config, db_file=None):
|
||||||
except (web.GracefulExit, KeyboardInterrupt, asyncio.CancelledError, ValueError):
|
except (web.GracefulExit, KeyboardInterrupt, asyncio.CancelledError, ValueError):
|
||||||
logging.warning('Server going down, asyncio loop raised cancelled error:')
|
logging.warning('Server going down, asyncio loop raised cancelled error:')
|
||||||
finally:
|
finally:
|
||||||
loop.run_until_complete(comment_app.stop())
|
loop.run_until_complete(comment_app.stop())
|
||||||
|
|
|
@ -31,14 +31,14 @@ def get_claim_comments(conn: sqlite3.Connection, claim_id: str, parent_id: str =
|
||||||
FROM COMMENTS_ON_CLAIMS
|
FROM COMMENTS_ON_CLAIMS
|
||||||
WHERE claim_id = ? AND parent_id IS NULL
|
WHERE claim_id = ? AND parent_id IS NULL
|
||||||
LIMIT ? OFFSET ? """,
|
LIMIT ? OFFSET ? """,
|
||||||
(claim_id, page_size, page_size*(page - 1))
|
(claim_id, page_size, page_size * (page - 1))
|
||||||
)]
|
)]
|
||||||
count = conn.execute(
|
count = conn.execute(
|
||||||
"""
|
"""
|
||||||
SELECT COUNT(*)
|
SELECT COUNT(*)
|
||||||
FROM COMMENTS_ON_CLAIMS
|
FROM COMMENTS_ON_CLAIMS
|
||||||
WHERE claim_id = ? AND parent_id IS NULL
|
WHERE claim_id = ? AND parent_id IS NULL
|
||||||
""", (claim_id, )
|
""", (claim_id,)
|
||||||
)
|
)
|
||||||
elif parent_id is None:
|
elif parent_id is None:
|
||||||
results = [clean(dict(row)) for row in conn.execute(
|
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
|
FROM COMMENTS_ON_CLAIMS
|
||||||
WHERE claim_id = ?
|
WHERE claim_id = ?
|
||||||
LIMIT ? OFFSET ? """,
|
LIMIT ? OFFSET ? """,
|
||||||
(claim_id, page_size, page_size*(page - 1))
|
(claim_id, page_size, page_size * (page - 1))
|
||||||
)]
|
)]
|
||||||
count = conn.execute(
|
count = conn.execute(
|
||||||
"""
|
"""
|
||||||
|
@ -63,7 +63,7 @@ def get_claim_comments(conn: sqlite3.Connection, claim_id: str, parent_id: str =
|
||||||
FROM COMMENTS_ON_CLAIMS
|
FROM COMMENTS_ON_CLAIMS
|
||||||
WHERE claim_id = ? AND parent_id = ?
|
WHERE claim_id = ? AND parent_id = ?
|
||||||
LIMIT ? OFFSET ? """,
|
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(
|
count = conn.execute(
|
||||||
"""
|
"""
|
||||||
|
@ -77,7 +77,7 @@ def get_claim_comments(conn: sqlite3.Connection, claim_id: str, parent_id: str =
|
||||||
'items': results,
|
'items': results,
|
||||||
'page': page,
|
'page': page,
|
||||||
'page_size': page_size,
|
'page_size': page_size,
|
||||||
'total_pages': math.ceil(count/page_size),
|
'total_pages': math.ceil(count / page_size),
|
||||||
'total_items': count
|
'total_items': count
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
import json
|
import json
|
||||||
import pathlib
|
import pathlib
|
||||||
|
|
||||||
|
|
||||||
root_dir = pathlib.Path(__file__).parent.parent
|
root_dir = pathlib.Path(__file__).parent.parent
|
||||||
config_path = root_dir / 'config' / 'conf.json'
|
config_path = root_dir / 'config' / 'conf.json'
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue