This commit is contained in:
parent
a7f14ee473
commit
f12d2fc560
|
@ -1,7 +1,7 @@
|
||||||
import json
|
import json
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from sqlalchemy import select, or_, and_, text, desc
|
from sqlalchemy import select, or_, and_, text, desc, cast, Integer
|
||||||
from sqlalchemy.orm import aliased
|
from sqlalchemy.orm import aliased
|
||||||
from sqlalchemy_searchable import search
|
from sqlalchemy_searchable import search
|
||||||
|
|
||||||
|
@ -45,18 +45,16 @@ async def get_author(_, _info, slug='', author_id=None):
|
||||||
|
|
||||||
if slug:
|
if slug:
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
aliased_author = aliased(Author)
|
q = select(Author).filter(Author.slug == slug)
|
||||||
q = select(aliased_author).filter(aliased_author.slug == slug)
|
|
||||||
[author] = session.execute(q)
|
[author] = session.execute(q)
|
||||||
author_id = aliased_author.id
|
author_id = cast(Author.id, Integer)
|
||||||
|
|
||||||
if author_id:
|
if author_id:
|
||||||
cache = await redis.execute('GET', f'id:{author_id}:author')
|
cache = await redis.execute('GET', f'id:{author_id}:author')
|
||||||
author = json.loads(cache)
|
author = json.loads(cache)
|
||||||
|
|
||||||
if not author:
|
if not author:
|
||||||
aliased_author = aliased(Author)
|
q = select(Author).where(Author.id == author_id)
|
||||||
q = select(aliased_author).where(aliased_author.id == author_id)
|
|
||||||
[author] = get_with_stat(q)
|
[author] = get_with_stat(q)
|
||||||
if author:
|
if author:
|
||||||
await update_author_cache(author.dict())
|
await update_author_cache(author.dict())
|
||||||
|
|
Loading…
Reference in New Issue
Block a user