Merge branch 'main' of github.com:Discours/discours-backend-next
This commit is contained in:
commit
1bfb3f352f
|
@ -95,25 +95,15 @@ class TopShouts:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def prepare_recent_shouts():
|
async def prepare_recent_shouts():
|
||||||
# TODO: debug recent shoputs resolver
|
|
||||||
month_ago = datetime.now() - timedelta(days = 30)
|
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
stmt = select(\
|
stmt = select(Shout).\
|
||||||
Shout,\
|
|
||||||
func.sum(ShoutViewByDay.value).label("view"),\
|
|
||||||
func.sum(ShoutRating.value).label("rating")\
|
|
||||||
).\
|
|
||||||
join(ShoutViewByDay).\
|
|
||||||
join(ShoutRating).\
|
|
||||||
where(Shout.createdAt > month_ago).\
|
|
||||||
group_by(Shout.id).\
|
|
||||||
order_by(desc("createdAt")).\
|
order_by(desc("createdAt")).\
|
||||||
limit(TopShouts.limit)
|
limit(TopShouts.limit)
|
||||||
shouts = []
|
shouts = []
|
||||||
for row in session.execute(stmt):
|
for row in session.execute(stmt):
|
||||||
shout = row.Shout
|
shout = row.Shout
|
||||||
shout.view = row.view
|
shout.rating = await ShoutRatingStorage.get_rating(shout.id)
|
||||||
shout.rating = row.rating
|
shout.views = await ShoutViewStorage.get_view(shout.id)
|
||||||
shouts.append(shout)
|
shouts.append(shout)
|
||||||
async with TopShouts.lock:
|
async with TopShouts.lock:
|
||||||
TopShouts.recent_shouts = shouts
|
TopShouts.recent_shouts = shouts
|
||||||
|
|
Loading…
Reference in New Issue
Block a user