slugs fix, dev friendly, readme

This commit is contained in:
tonyrewin 2022-05-31 10:03:50 +03:00
parent 1bd868b800
commit 8e57e8b7fb
5 changed files with 32 additions and 32 deletions

View File

@ -9,24 +9,24 @@ Tech stack:
# 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 brew services start redis
``` ```
Create certificate files on debian/ubuntu
```
```sh apt install redis python-poetry
./create_crt.sh
``` ```
Then run API server Then run API server
``` ```
pipenv install poetry install
pipenv run python server.py poetry run python server.py
``` ```
Also see `Dockerfile` Also see `Dockerfile`

View File

@ -7,7 +7,11 @@ from sqlalchemy.sql.schema import Table
from settings import DB_URL from settings import DB_URL
engine = create_engine(DB_URL, convert_unicode=True, echo=False, \ 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) pool_size=10, max_overflow=20)
T = TypeVar("T") T = TypeVar("T")

View File

@ -1,6 +1,6 @@
from resolvers.auth import login, sign_out, is_email_free, register, confirm 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, \ from resolvers.zine import create_shout, get_shout_by_slug, \
recent_shouts, top_viewed, shouts_by_author, shouts_by_topic, \ top_month, top_overall, recent_shouts, top_viewed, shouts_by_authors, shouts_by_topics, shouts_by_communities, \
shouts_candidates, shouts_reviewed, shouts_subscribed shouts_candidates, shouts_reviewed, shouts_subscribed
from resolvers.profile import get_users_by_slugs, get_current_user from resolvers.profile import get_users_by_slugs, get_current_user
from resolvers.topics import topic_subscribe, topic_unsubscribe, topics_by_author, \ from resolvers.topics import topic_subscribe, topic_unsubscribe, topics_by_author, \
@ -20,8 +20,9 @@ __all__ = [
"get_users_by_slugs", "get_users_by_slugs",
"get_shout_by_slug", "get_shout_by_slug",
"recent_shouts", "recent_shouts",
"shouts_by_topic", "shouts_by_topics",
"shouts_by_author", "shouts_by_authors",
"shouts_by_communities",
"shouts_subscribed", "shouts_subscribed",
"shouts_reviewed", "shouts_reviewed",
"shouts_candidates", "shouts_candidates",

View File

@ -376,38 +376,33 @@ async def get_shout_comments(_, info, slug):
comment.author = await UserStorage.get_user(comment.author) comment.author = await UserStorage.get_user(comment.author)
return comments return comments
@query.field("shoutsByTopic") @query.field("shoutsByTopics")
async def shouts_by_topic(_, info, topic, page, size): async def shouts_by_topics(_, info, slugs, page, size):
page = page - 1 page = page - 1
with local_session() as session: with local_session() as session:
shouts = session.query(Shout).\ shouts = session.query(Shout).\
join(ShoutTopic).\ join(ShoutTopic).\
where(and_(ShoutTopic.topic == topic, Shout.publishedAt != None)).\ where(and_(ShoutTopic.topic.in_(slugs), Shout.publishedAt != None)).\
order_by(desc(Shout.publishedAt)).\ order_by(desc(Shout.publishedAt)).\
limit(size).\ limit(size).\
offset(page * size) offset(page * size)
return shouts return shouts
@query.field("shoutsByAuthor") @query.field("shoutsByAuthors")
async def shouts_by_author(_, info, author, page, size): async def shouts_by_authors(_, info, slugs, page, size):
page = page - 1 page = page - 1
with local_session() as session: 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).\ shouts = session.query(Shout).\
join(ShoutAuthor).\ join(ShoutAuthor).\
where(and_(ShoutAuthor.user == author, Shout.publishedAt != None)).\ where(and_(ShoutAuthor.user.in_(slugs), Shout.publishedAt != None)).\
order_by(desc(Shout.publishedAt)).\ order_by(desc(Shout.publishedAt)).\
limit(size).\ limit(size).\
offset(page * size) offset(page * size)
return shouts return shouts
@query.field("shoutsByCommunity") @query.field("shoutsByCommunities")
async def shouts_by_community(_, info, community, page, size): async def shouts_by_communities(_, info, slugs, page, size):
page = page - 1 page = page - 1
with local_session() as session: with local_session() as session:
#TODO fix postgres high load #TODO fix postgres high load
@ -415,7 +410,7 @@ async def shouts_by_community(_, info, community, page, size):
join(ShoutTopic).\ join(ShoutTopic).\
where(and_(Shout.publishedAt != None,\ where(and_(Shout.publishedAt != None,\
ShoutTopic.topic.in_(\ ShoutTopic.topic.in_(\
select(Topic.slug).where(Topic.community == community)\ select(Topic.slug).where(Topic.community.in_(slugs))\
))).\ ))).\
order_by(desc(Shout.publishedAt)).\ order_by(desc(Shout.publishedAt)).\
limit(size).\ limit(size).\

View File

@ -157,9 +157,9 @@ type Query {
# shouts # shouts
getShoutBySlug(slug: String!): Shout! getShoutBySlug(slug: String!): Shout!
shoutsByTopic(topic: String!, page: Int!, size: Int!): [Shout]! shoutsByTopics(slugs: [String]!, page: Int!, size: Int!): [Shout]!
shoutsByAuthor(author: String!, page: Int!, size: Int!): [Shout]! shoutsByAuthors(slugs: [String]!, page: Int!, size: Int!): [Shout]!
shoutsByCommunity(community: String!, page: Int!, size: Int!): [Shout]! shoutsByCommunities(slugs: [String]!, page: Int!, size: Int!): [Shout]!
getShoutComments(slug: String!): [Comment]! getShoutComments(slug: String!): [Comment]!
# mainpage # mainpage