diff --git a/README.md b/README.md index 8a749e00..8b30a670 100644 --- a/README.md +++ b/README.md @@ -7,26 +7,26 @@ Tech stack: - ariadne - starlette -# Local development +# Local development -Install redis and pipenv first +Install redis and poetry (or any python env manager) first +on osx ``` -brew install redis pipenv +brew install redis poetry brew services start redis ``` -Create certificate files - -```sh -./create_crt.sh +on debian/ubuntu +``` +apt install redis python-poetry ``` Then run API server ``` -pipenv install -pipenv run python server.py +poetry install +poetry run python server.py ``` Also see `Dockerfile` diff --git a/orm/base.py b/orm/base.py index 1d6b4d95..63ce30d4 100644 --- a/orm/base.py +++ b/orm/base.py @@ -7,8 +7,12 @@ from sqlalchemy.sql.schema import Table from settings import DB_URL -engine = create_engine(DB_URL, convert_unicode=True, echo=False, \ - pool_size=10, max_overflow=20) +if not DB_URL.startswith('sqlite'): + engine = create_engine(DB_URL) +else: + + engine = create_engine(DB_URL, convert_unicode=True, echo=False, \ + pool_size=10, max_overflow=20) T = TypeVar("T") diff --git a/resolvers/__init__.py b/resolvers/__init__.py index 33098b93..3ec261df 100644 --- a/resolvers/__init__.py +++ b/resolvers/__init__.py @@ -1,6 +1,6 @@ from resolvers.auth import login, sign_out, is_email_free, register, confirm -from resolvers.zine import create_shout, get_shout_by_slug, top_month, top_overall, \ - recent_shouts, top_viewed, shouts_by_author, shouts_by_topic, \ +from resolvers.zine import create_shout, get_shout_by_slug, \ + top_month, top_overall, recent_shouts, top_viewed, shouts_by_authors, shouts_by_topics, shouts_by_communities, \ shouts_candidates, shouts_reviewed, shouts_subscribed from resolvers.profile import get_users_by_slugs, get_current_user from resolvers.topics import topic_subscribe, topic_unsubscribe, topics_by_author, \ @@ -20,8 +20,9 @@ __all__ = [ "get_users_by_slugs", "get_shout_by_slug", "recent_shouts", - "shouts_by_topic", - "shouts_by_author", + "shouts_by_topics", + "shouts_by_authors", + "shouts_by_communities", "shouts_subscribed", "shouts_reviewed", "shouts_candidates", diff --git a/resolvers/zine.py b/resolvers/zine.py index 9b3f73dd..c74a0a68 100644 --- a/resolvers/zine.py +++ b/resolvers/zine.py @@ -376,38 +376,33 @@ async def get_shout_comments(_, info, slug): comment.author = await UserStorage.get_user(comment.author) return comments -@query.field("shoutsByTopic") -async def shouts_by_topic(_, info, topic, page, size): +@query.field("shoutsByTopics") +async def shouts_by_topics(_, info, slugs, page, size): page = page - 1 with local_session() as session: shouts = session.query(Shout).\ join(ShoutTopic).\ - where(and_(ShoutTopic.topic == topic, Shout.publishedAt != None)).\ + where(and_(ShoutTopic.topic.in_(slugs), Shout.publishedAt != None)).\ order_by(desc(Shout.publishedAt)).\ limit(size).\ offset(page * size) return shouts -@query.field("shoutsByAuthor") -async def shouts_by_author(_, info, author, page, size): +@query.field("shoutsByAuthors") +async def shouts_by_authors(_, info, slugs, page, size): page = page - 1 with local_session() as session: - user = session.query(User).\ - filter(User.slug == author).first() - if not user: - print("author not exist") - return shouts = session.query(Shout).\ join(ShoutAuthor).\ - where(and_(ShoutAuthor.user == author, Shout.publishedAt != None)).\ + where(and_(ShoutAuthor.user.in_(slugs), Shout.publishedAt != None)).\ order_by(desc(Shout.publishedAt)).\ limit(size).\ offset(page * size) return shouts -@query.field("shoutsByCommunity") -async def shouts_by_community(_, info, community, page, size): +@query.field("shoutsByCommunities") +async def shouts_by_communities(_, info, slugs, page, size): page = page - 1 with local_session() as session: #TODO fix postgres high load @@ -415,7 +410,7 @@ async def shouts_by_community(_, info, community, page, size): join(ShoutTopic).\ where(and_(Shout.publishedAt != None,\ ShoutTopic.topic.in_(\ - select(Topic.slug).where(Topic.community == community)\ + select(Topic.slug).where(Topic.community.in_(slugs))\ ))).\ order_by(desc(Shout.publishedAt)).\ limit(size).\ diff --git a/schema.graphql b/schema.graphql index 05d158de..d837e30f 100644 --- a/schema.graphql +++ b/schema.graphql @@ -157,9 +157,9 @@ type Query { # shouts getShoutBySlug(slug: String!): Shout! - shoutsByTopic(topic: String!, page: Int!, size: Int!): [Shout]! - shoutsByAuthor(author: String!, page: Int!, size: Int!): [Shout]! - shoutsByCommunity(community: String!, page: Int!, size: Int!): [Shout]! + shoutsByTopics(slugs: [String]!, page: Int!, size: Int!): [Shout]! + shoutsByAuthors(slugs: [String]!, page: Int!, size: Int!): [Shout]! + shoutsByCommunities(slugs: [String]!, page: Int!, size: Int!): [Shout]! getShoutComments(slug: String!): [Comment]! # mainpage