my feed query fixed
This commit is contained in:
parent
d7dd79336b
commit
34d04e4240
23
README.md
23
README.md
|
@ -7,10 +7,6 @@
|
||||||
- starlette
|
- starlette
|
||||||
- uvicorn
|
- uvicorn
|
||||||
|
|
||||||
# Local development
|
|
||||||
|
|
||||||
Install deps first
|
|
||||||
|
|
||||||
on osx
|
on osx
|
||||||
```
|
```
|
||||||
brew install redis nginx postgres
|
brew install redis nginx postgres
|
||||||
|
@ -22,16 +18,23 @@ on debian/ubuntu
|
||||||
apt install redis nginx
|
apt install redis nginx
|
||||||
```
|
```
|
||||||
|
|
||||||
First, install Postgres. Then you'll need some data, so migrate it:
|
# Local development
|
||||||
|
|
||||||
|
Install deps first
|
||||||
|
|
||||||
```
|
```
|
||||||
createdb discoursio
|
pip install -r requirements.txt
|
||||||
python server.py migrate
|
pip install -r requirements-dev.txt
|
||||||
|
pre-commit install
|
||||||
```
|
```
|
||||||
|
|
||||||
Then run nginx, redis and API server
|
Create database from backup
|
||||||
|
```
|
||||||
|
./restdb.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
Start local server
|
||||||
```
|
```
|
||||||
redis-server
|
|
||||||
pip install -r requirements.txt
|
|
||||||
python3 server.py dev
|
python3 server.py dev
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -210,12 +210,17 @@ async def get_my_feed(_, info, options):
|
||||||
auth: AuthCredentials = info.context["request"].auth
|
auth: AuthCredentials = info.context["request"].auth
|
||||||
user_id = auth.user_id
|
user_id = auth.user_id
|
||||||
|
|
||||||
|
user_followed_authors = select(AuthorFollower.author).where(AuthorFollower.follower == user_id)
|
||||||
|
user_followed_topics = select(TopicFollower.topic).where(TopicFollower.follower == user_id)
|
||||||
|
|
||||||
subquery = (
|
subquery = (
|
||||||
select(Shout.id)
|
select(Shout.id)
|
||||||
.join(ShoutAuthor)
|
.where(Shout.id == ShoutAuthor.shout)
|
||||||
.join(AuthorFollower, AuthorFollower.follower == user_id)
|
.where(Shout.id == ShoutTopic.shout)
|
||||||
.join(ShoutTopic)
|
.where(
|
||||||
.join(TopicFollower, TopicFollower.follower == user_id)
|
(ShoutAuthor.user.in_(user_followed_authors))
|
||||||
|
| (ShoutTopic.topic.in_(user_followed_topics))
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
q = (
|
q = (
|
||||||
|
@ -240,9 +245,10 @@ async def get_my_feed(_, info, options):
|
||||||
|
|
||||||
q = q.group_by(Shout.id).order_by(nulls_last(query_order_by)).limit(limit).offset(offset)
|
q = q.group_by(Shout.id).order_by(nulls_last(query_order_by)).limit(limit).offset(offset)
|
||||||
|
|
||||||
|
# print(q.compile(compile_kwargs={"literal_binds": True}))
|
||||||
|
|
||||||
shouts = []
|
shouts = []
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
shouts_map = {}
|
|
||||||
for [shout, reacted_stat, commented_stat, rating_stat, last_comment] in session.execute(
|
for [shout, reacted_stat, commented_stat, rating_stat, last_comment] in session.execute(
|
||||||
q
|
q
|
||||||
).unique():
|
).unique():
|
||||||
|
@ -253,6 +259,5 @@ async def get_my_feed(_, info, options):
|
||||||
"commented": commented_stat,
|
"commented": commented_stat,
|
||||||
"rating": rating_stat,
|
"rating": rating_stat,
|
||||||
}
|
}
|
||||||
shouts_map[shout.id] = shout
|
|
||||||
|
|
||||||
return shouts
|
return shouts
|
||||||
|
|
Loading…
Reference in New Issue
Block a user