ShoutViewStorage refactor
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
from orm import Shout, ShoutAuthor, ShoutTopic, ShoutRating, ShoutViewByDay, User, Community, Resource,\
|
||||
rating_storage, view_storage
|
||||
rating_storage, ShoutViewStorage
|
||||
from orm.base import local_session
|
||||
|
||||
from resolvers.base import mutation, query
|
||||
@@ -165,17 +165,6 @@ class TopShouts:
|
||||
print("top shouts worker error = %s" % (err))
|
||||
await asyncio.sleep(TopShouts.period)
|
||||
|
||||
async def db_flush_worker():
|
||||
print("db flush worker start")
|
||||
while True:
|
||||
try:
|
||||
print("flush changes")
|
||||
with local_session() as session:
|
||||
view_storage.flush_changes(session)
|
||||
except Exception as err:
|
||||
print("db flush worker error = %s" % (err))
|
||||
await asyncio.sleep(30*60)
|
||||
|
||||
|
||||
@query.field("topShoutsByView")
|
||||
async def top_shouts_by_view(_, info, limit):
|
||||
@@ -297,7 +286,7 @@ async def rate_shout(_, info, shout_id, value):
|
||||
|
||||
@mutation.field("viewShout")
|
||||
async def view_shout(_, info, shout_id):
|
||||
view_storage.inc_view(shout_id)
|
||||
await ShoutViewStorage.inc_view(shout_id)
|
||||
return {"error" : ""}
|
||||
|
||||
@query.field("getShoutBySlug")
|
||||
@@ -311,5 +300,5 @@ async def get_shout_by_slug(_, info, slug):
|
||||
options(select_options).\
|
||||
filter(Shout.slug == slug).first()
|
||||
shout.rating = rating_storage.get_rating(shout.id)
|
||||
shout.views = view_storage.get_view(shout.id)
|
||||
shout.views = await ShoutViewStorage.get_view(shout.id)
|
||||
return shout
|
||||
|
Reference in New Issue
Block a user