precache-synced-with-cache
All checks were successful
Deploy on push / deploy (push) Successful in 1m9s
All checks were successful
Deploy on push / deploy (push) Successful in 1m9s
This commit is contained in:
parent
1cc779e17b
commit
85f63a0e17
|
@ -6,6 +6,7 @@ from orm.author import Author, AuthorFollower
|
||||||
from orm.shout import Shout, ShoutAuthor, ShoutTopic
|
from orm.shout import Shout, ShoutAuthor, ShoutTopic
|
||||||
from orm.topic import Topic, TopicFollower
|
from orm.topic import Topic, TopicFollower
|
||||||
from resolvers.stat import get_with_stat
|
from resolvers.stat import get_with_stat
|
||||||
|
from services.cache import cache_author, cache_topic
|
||||||
from services.db import local_session
|
from services.db import local_session
|
||||||
from services.encoders import CustomJSONEncoder
|
from services.encoders import CustomJSONEncoder
|
||||||
from services.logger import root_logger as logger
|
from services.logger import root_logger as logger
|
||||||
|
@ -110,12 +111,7 @@ async def precache_data():
|
||||||
topics = get_with_stat(select(Topic))
|
topics = get_with_stat(select(Topic))
|
||||||
for topic in topics:
|
for topic in topics:
|
||||||
topic_profile = topic.dict() if not isinstance(topic, dict) else topic
|
topic_profile = topic.dict() if not isinstance(topic, dict) else topic
|
||||||
topic_id = topic_profile.get("id")
|
await cache_topic(topic_profile)
|
||||||
topics_by_id[topic_id] = topic_profile
|
|
||||||
topic_slug = topic_profile["slug"]
|
|
||||||
topic_payload = json.dumps(topic_profile, cls=CustomJSONEncoder)
|
|
||||||
await redis.execute("SET", f"topic:id:{topic_id}", topic_payload)
|
|
||||||
await redis.execute("SET", f"topic:slug:{topic_slug}", topic_payload)
|
|
||||||
logger.info(f"{len(topics)} topics precached")
|
logger.info(f"{len(topics)} topics precached")
|
||||||
|
|
||||||
# followings for topics
|
# followings for topics
|
||||||
|
@ -134,11 +130,9 @@ async def precache_data():
|
||||||
user_id = profile.get("user","").strip()
|
user_id = profile.get("user","").strip()
|
||||||
if author_id and user_id:
|
if author_id and user_id:
|
||||||
authors_by_id[author_id] = profile
|
authors_by_id[author_id] = profile
|
||||||
author_payload = json.dumps(profile, cls=CustomJSONEncoder)
|
await cache_author(profile)
|
||||||
await redis.execute("SET", f"author:id:{author_id}", author_payload)
|
|
||||||
await redis.execute("SET", f"author:user:{user_id.strip()}", author_id)
|
|
||||||
else:
|
else:
|
||||||
logger.error(f"caching {author.dict()}")
|
logger.error(f"fail caching {author.dict()}")
|
||||||
logger.info(f"{len(authors)} authors precached")
|
logger.info(f"{len(authors)} authors precached")
|
||||||
|
|
||||||
# followings for authors
|
# followings for authors
|
||||||
|
|
Loading…
Reference in New Issue
Block a user