This commit is contained in:
Untone 2024-04-17 20:30:05 +03:00
parent 372185e336
commit 47bc3adb69
3 changed files with 9 additions and 4 deletions

View File

@ -32,6 +32,8 @@ async def update_author(_, info, profile):
Author.update(author, profile) Author.update(author, profile)
session.add(author) session.add(author)
session.commit() session.commit()
[author] = get_with_stat(select(Author).where(Author.user == user_id))
await cache_author(author.dict())
return {"error": None, "author": author} return {"error": None, "author": author}
except Exception as exc: except Exception as exc:
import traceback import traceback

View File

@ -21,7 +21,7 @@ async def cache_author(author: dict):
# update stat all field for followers' caches in <authors> list # update stat all field for followers' caches in <authors> list
followers_str = await redis.execute("GET", f'author:{author.get("id")}:followers') followers_str = await redis.execute("GET", f'author:{author.get("id")}:followers')
followers = [] followers = []
if followers_str: if isinstance(followers_str, str):
followers = json.loads(followers_str) followers = json.loads(followers_str)
if isinstance(followers, list): if isinstance(followers, list):
for follower in followers: for follower in followers:

View File

@ -36,16 +36,19 @@ class WebhookEndpoint(HTTPEndpoint):
email: str = user.get("email", "") email: str = user.get("email", "")
pic: str = user.get("picture", "") pic: str = user.get("picture", "")
if user_id: if user_id:
with local_session() as session: with local_session() as session:
author = session.query(Author).filter(Author.user == user_id).first() author = (
session.query(Author).filter(Author.user == user_id).first()
)
if not author: if not author:
# If the author does not exist, create a new one # If the author does not exist, create a new one
slug: str = email.split("@")[0].replace(".", "-").lower() slug: str = email.split("@")[0].replace(".", "-").lower()
slug: str = re.sub("[^0-9a-z]+", "-", slug) slug: str = re.sub("[^0-9a-z]+", "-", slug)
while True: while True:
author = ( author = (
session.query(Author).filter(Author.slug == slug).first() session.query(Author)
.filter(Author.slug == slug)
.first()
) )
if not author: if not author:
break break