diff --git a/README.md b/README.md new file mode 100644 index 0000000..4a88e32 --- /dev/null +++ b/README.md @@ -0,0 +1,23 @@ +# LBRY Comment Server v2 + +This is a rewrite & update of the server +[written by myself and Grayson Burton here](https://github.com/ocornoc/lbry-comments) + + +A lot of the design is more or less the same with the original, +except this version focuses less on performance and more on scalability. + +Rewritten with python because it's easier to adjust +and maintain. Instead of doing any multithreading, +this implementation just delegates a single +database connection for write operations. + +The server was originally implemented with `aiohttp` +and uses `aiojobs` for scheduling write operations. +As pointed out by several people, Python is a dinosaur +in comparison to SQLite's execution speed, +so there is no sensibility in multi-threading from the +perspective of the server code itself. + +The schema for + diff --git a/lbry_comment_server/__init__.py b/lbry_comment_server/__init__.py index 216173b..b28b04f 100644 --- a/lbry_comment_server/__init__.py +++ b/lbry_comment_server/__init__.py @@ -1,6 +1,3 @@ -from lbry_comment_server.database import obtain_connection, validate_input, get_claim_comments -from lbry_comment_server.database import get_comments_by_id, get_comment_ids, create_comment -from lbry_comment_server.handles import api_endpoint -from lbry_comment_server.settings import config + diff --git a/lbry_comment_server/database.py b/lbry_comment_server/database.py index db958e4..da231d5 100644 --- a/lbry_comment_server/database.py +++ b/lbry_comment_server/database.py @@ -1,10 +1,12 @@ -import sqlite3 -import aiosqlite -import typing -import re -import nacl.hash -import time import logging +import re +import sqlite3 +import time +import typing + +import aiosqlite +import nacl.hash + from lbry_comment_server.settings import config logger = logging.getLogger(__name__) diff --git a/lbry_comment_server/handles.py b/lbry_comment_server/handles.py index 21acceb..f55b21c 100644 --- a/lbry_comment_server/handles.py +++ b/lbry_comment_server/handles.py @@ -1,13 +1,14 @@ import json -import asyncio -from aiojobs.aiohttp import atomic -from aiohttp import web import logging -from lbry_comment_server.database import obtain_connection + +import asyncio +from aiohttp import web +from aiojobs.aiohttp import atomic + +import lbry_comment_server.writes as writes from lbry_comment_server import get_claim_comments from lbry_comment_server import get_comments_by_id, get_comment_ids -import lbry_comment_server.writes as writes - +from lbry_comment_server.database import obtain_connection logger = logging.getLogger(__name__) diff --git a/lbry_comment_server/main.py b/lbry_comment_server/main.py index 42f4055..f062221 100644 --- a/lbry_comment_server/main.py +++ b/lbry_comment_server/main.py @@ -1,14 +1,14 @@ -import asyncio -from aiohttp import web -import aiojobs.aiohttp import logging -import schema.db_helpers as helpers -import lbry_comment_server.writes as writes -from lbry_comment_server.settings import config -from lbry_comment_server.handles import api_endpoint -from lbry_comment_server.database import obtain_connection +import aiojobs.aiohttp +import asyncio +from aiohttp import web +import lbry_comment_server.writes as writes +import schema.db_helpers as helpers +from lbry_comment_server.database import obtain_connection +from lbry_comment_server.handles import api_endpoint +from lbry_comment_server.settings import config logger = logging.getLogger(__name__) logger.setLevel(logging.DEBUG) diff --git a/lbry_comment_server/settings.py b/lbry_comment_server/settings.py index ac8e014..6f6c3e7 100644 --- a/lbry_comment_server/settings.py +++ b/lbry_comment_server/settings.py @@ -1,6 +1,6 @@ import json -import pathlib import logging +import pathlib logger = logging.getLogger(__name__) diff --git a/lbry_comment_server/writes.py b/lbry_comment_server/writes.py index a2a6f2e..fd841ee 100644 --- a/lbry_comment_server/writes.py +++ b/lbry_comment_server/writes.py @@ -1,10 +1,11 @@ -import aiojobs import atexit -from asyncio import coroutine -import lbry_comment_server.database as db - import logging +import aiojobs +from asyncio import coroutine + +import lbry_comment_server.database as db + logger = logging.getLogger(__name__) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..301dbde --- /dev/null +++ b/requirements.txt @@ -0,0 +1,5 @@ +faker +asyncio +aiohttp +aiojobs +aiosqlite diff --git a/tests/database_test.py b/tests/database_test.py index ff7ea55..e862f62 100644 --- a/tests/database_test.py +++ b/tests/database_test.py @@ -1,10 +1,10 @@ from random import randint + import faker from faker.providers import internet from faker.providers import lorem from faker.providers import misc - import lbry_comment_server.database as db import schema.db_helpers as schema from lbry_comment_server.settings import config diff --git a/tests/testcase.py b/tests/testcase.py index 26f34ed..0eec06d 100644 --- a/tests/testcase.py +++ b/tests/testcase.py @@ -1,11 +1,12 @@ -import asyncio -from asyncio.runners import _cancel_all_tasks # type: ignore import unittest +from asyncio.runners import _cancel_all_tasks # type: ignore from unittest.case import _Outcome -import lbry_comment_server.database as db -from lbry_comment_server import config +import asyncio + +import lbry_comment_server.database as db import schema.db_helpers as schema +from lbry_comment_server.settings import config class AsyncioTestCase(unittest.TestCase):