author-with-stat-cache-nonblock-2
Some checks failed
Deploy on push / deploy (push) Failing after 9s
Some checks failed
Deploy on push / deploy (push) Failing after 9s
This commit is contained in:
parent
b2fdc9a453
commit
04e20b29ee
|
@ -1,3 +1,5 @@
|
||||||
|
import asyncio
|
||||||
|
|
||||||
from sqlalchemy import and_, distinct, func, join, select
|
from sqlalchemy import and_, distinct, func, join, select
|
||||||
from sqlalchemy.orm import aliased
|
from sqlalchemy.orm import aliased
|
||||||
|
|
||||||
|
@ -260,9 +262,12 @@ def author_follows_topics(author_id: int):
|
||||||
async def update_author_stat(author_id: int):
|
async def update_author_stat(author_id: int):
|
||||||
author_query = select(Author).where(Author.id == author_id)
|
author_query = select(Author).where(Author.id == author_id)
|
||||||
try:
|
try:
|
||||||
[author_with_stat] = get_with_stat(author_query)
|
result = get_with_stat(author_query)
|
||||||
|
if result and len(result) == 1:
|
||||||
|
author_with_stat = result[0]
|
||||||
if isinstance(author_with_stat, Author):
|
if isinstance(author_with_stat, Author):
|
||||||
author_dict = author_with_stat.dict()
|
author_dict = author_with_stat.dict()
|
||||||
await cache_author(author_dict)
|
# await cache_author(author_dict)
|
||||||
|
asyncio.create_task(cache_author(author_dict))
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
logger.error(exc, exc_info=True)
|
logger.error(exc, exc_info=True)
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import asyncio
|
||||||
import json
|
import json
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
|
@ -81,11 +82,12 @@ async def get_cached_author_by_user_id(user_id: str, get_with_stat) -> dict:
|
||||||
if not author_id:
|
if not author_id:
|
||||||
author_query = select(Author).filter(Author.user == user_id)
|
author_query = select(Author).filter(Author.user == user_id)
|
||||||
result = get_with_stat(author_query)
|
result = get_with_stat(author_query)
|
||||||
if result:
|
if result and len(result) == 1:
|
||||||
[author_with_stat] = result
|
author_with_stat = result[0]
|
||||||
if author_with_stat:
|
if isinstance(author_with_stat, Author):
|
||||||
await cache_author(author_with_stat.dict())
|
|
||||||
author_dict = author_with_stat.dict()
|
author_dict = author_with_stat.dict()
|
||||||
|
# await cache_author(author_dict)
|
||||||
|
asyncio.create_task(cache_author(author_dict))
|
||||||
else:
|
else:
|
||||||
author_str = await redis.execute("GET", f"author:id:{author_id}")
|
author_str = await redis.execute("GET", f"author:id:{author_id}")
|
||||||
if author_str:
|
if author_str:
|
||||||
|
|
|
@ -66,9 +66,14 @@ def after_reaction_update(mapper, connection, reaction: Reaction):
|
||||||
try:
|
try:
|
||||||
# reaction author
|
# reaction author
|
||||||
author_subquery = select(Author).where(Author.id == reaction.created_by)
|
author_subquery = select(Author).where(Author.id == reaction.created_by)
|
||||||
[author_with_stat] = get_with_stat(author_subquery)
|
|
||||||
|
result = get_with_stat(author_subquery)
|
||||||
|
if result and len(result) == 1:
|
||||||
|
author_with_stat = result[0]
|
||||||
if isinstance(author_with_stat, Author):
|
if isinstance(author_with_stat, Author):
|
||||||
asyncio.create_task(cache_author(author_with_stat.dict()))
|
author_dict = author_with_stat.dict()
|
||||||
|
# await cache_author(author_dict)
|
||||||
|
asyncio.create_task(cache_author(author_dict))
|
||||||
|
|
||||||
# reaction repliers
|
# reaction repliers
|
||||||
replied_author_subquery = (
|
replied_author_subquery = (
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import asyncio
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
@ -50,9 +51,12 @@ class WebhookEndpoint(HTTPEndpoint):
|
||||||
session.add(author)
|
session.add(author)
|
||||||
session.commit()
|
session.commit()
|
||||||
author_query = select(Author).filter(Author.user == user_id)
|
author_query = select(Author).filter(Author.user == user_id)
|
||||||
[author_with_stat] = get_with_stat(author_query)
|
result = get_with_stat(author_query)
|
||||||
if author_with_stat:
|
if result and len(result) == 1:
|
||||||
await cache_author(author_with_stat)
|
author_with_stat = result[0]
|
||||||
|
author_dict = author_with_stat.dict()
|
||||||
|
# await cache_author(author_with_stat)
|
||||||
|
asyncio.create_task(cache_author(author_dict))
|
||||||
|
|
||||||
return JSONResponse({"status": "success"})
|
return JSONResponse({"status": "success"})
|
||||||
except HTTPException as e:
|
except HTTPException as e:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user