return all rating for shout; unify rating fields

This commit is contained in:
knst-kotov
2021-12-14 19:37:49 +03:00
parent 64a728de41
commit 4f76f85bed
5 changed files with 23 additions and 12 deletions

View File

@@ -87,7 +87,7 @@ class ShoutsCache:
shouts = []
for row in session.execute(stmt):
shout = row.Shout
shout.rating = await ShoutRatingStorage.get_rating(shout.slug)
shout.ratings = await ShoutRatingStorage.get_ratings(shout.slug)
shout.views = await ShoutViewStorage.get_view(shout.slug)
shouts.append(shout)
async with ShoutsCache.lock:
@@ -107,7 +107,7 @@ class ShoutsCache:
shouts = []
for row in session.execute(stmt):
shout = row.Shout
shout.rating = row.rating
shout.ratings = await ShoutRatingStorage.get_ratings(shout.slug)
shout.views = await ShoutViewStorage.get_view(shout.slug)
shouts.append(shout)
async with ShoutsCache.lock:
@@ -127,7 +127,7 @@ class ShoutsCache:
shouts = []
for row in session.execute(stmt):
shout = row.Shout
shout.rating = row.rating
shout.ratings = await ShoutRatingStorage.get_ratings(shout.slug)
shout.views = await ShoutViewStorage.get_view(shout.slug)
shouts.append(shout)
async with ShoutsCache.lock:
@@ -147,7 +147,7 @@ class ShoutsCache:
shouts = []
for row in session.execute(stmt):
shout = row.Shout
shout.rating = await ShoutRatingStorage.get_rating(shout.slug)
shout.ratings = await ShoutRatingStorage.get_ratings(shout.slug)
shout.views = row.views
shouts.append(shout)
async with ShoutsCache.lock:
@@ -362,7 +362,12 @@ async def get_shout_by_slug(_, info, slug):
shout = session.query(Shout).\
options(select_options).\
filter(Shout.slug == slug).first()
shout.rating = await ShoutRatingStorage.get_rating(slug)
if not shout:
print("shout not exist")
return {} #TODO return error field
shout.ratings = await ShoutRatingStorage.get_ratings(slug)
shout.views = await ShoutViewStorage.get_view(slug)
return shout