cache-reform
This commit is contained in:
@@ -3,25 +3,25 @@ from sqlalchemy import distinct, func, select
|
||||
from orm.author import Author
|
||||
from orm.shout import ShoutTopic
|
||||
from orm.topic import Topic
|
||||
from resolvers.stat import get_with_stat
|
||||
from resolvers.stat import get_topics_with_stat_cached
|
||||
from services.auth import login_required
|
||||
from services.db import local_session
|
||||
from services.schema import mutation, query
|
||||
|
||||
|
||||
@query.field('get_topics_all')
|
||||
def get_topics_all(_, _info):
|
||||
return get_with_stat(select(Topic))
|
||||
async def get_topics_all(_, _info):
|
||||
return await get_topics_with_stat_cached(select(Topic))
|
||||
|
||||
|
||||
@query.field('get_topics_by_community')
|
||||
def get_topics_by_community(_, _info, community_id: int):
|
||||
async def get_topics_by_community(_, _info, community_id: int):
|
||||
q = select(Topic).where(Topic.community == community_id)
|
||||
return get_with_stat(q)
|
||||
return await get_topics_with_stat_cached(q)
|
||||
|
||||
|
||||
@query.field('get_topics_by_author')
|
||||
def get_topics_by_author(_, _info, author_id=0, slug='', user=''):
|
||||
async def get_topics_by_author(_, _info, author_id=0, slug='', user=''):
|
||||
q = select(Topic)
|
||||
if author_id:
|
||||
q = q.join(Author).where(Author.id == author_id)
|
||||
@@ -30,13 +30,13 @@ def get_topics_by_author(_, _info, author_id=0, slug='', user=''):
|
||||
elif user:
|
||||
q = q.join(Author).where(Author.user == user)
|
||||
|
||||
return get_with_stat(q)
|
||||
return await get_topics_with_stat_cached(q)
|
||||
|
||||
|
||||
@query.field('get_topic')
|
||||
def get_topic(_, _info, slug: str):
|
||||
async def get_topic(_, _info, slug: str):
|
||||
q = select(Topic).filter(Topic.slug == slug)
|
||||
topics = get_with_stat(q)
|
||||
topics = await get_topics_with_stat_cached(q)
|
||||
if topics:
|
||||
return topics[0]
|
||||
|
||||
|
Reference in New Issue
Block a user