This commit is contained in:
parent
658c8c7702
commit
dd2becaab2
|
@ -21,16 +21,14 @@ from services.schema import mutation, query
|
||||||
from services.search import search_service
|
from services.search import search_service
|
||||||
|
|
||||||
|
|
||||||
async def cache_by_id(what: str, entity_id: int):
|
async def cache_by_id(entity, entity_id: int):
|
||||||
is_author = what == "AUTHOR"
|
q = select(entity).filter(entity.id == entity_id)
|
||||||
alias = Author if is_author else Topic
|
|
||||||
q = select(alias).filter(alias.id == entity_id)
|
|
||||||
[x] = get_with_stat(q)
|
[x] = get_with_stat(q)
|
||||||
if not x:
|
if not x:
|
||||||
return
|
return
|
||||||
|
|
||||||
d = x.dict() # convert object to dictionary
|
d = x.dict() # convert object to dictionary
|
||||||
if is_author:
|
if entity == Author:
|
||||||
await cache_author(d)
|
await cache_author(d)
|
||||||
else:
|
else:
|
||||||
await cache_topic(d)
|
await cache_topic(d)
|
||||||
|
@ -300,7 +298,7 @@ async def update_shout(_, info, shout_id: int, shout_input=None, publish=False):
|
||||||
patch_topics(session, shout_by_id, topics_input)
|
patch_topics(session, shout_by_id, topics_input)
|
||||||
del shout_input["topics"]
|
del shout_input["topics"]
|
||||||
for tpc in topics_input:
|
for tpc in topics_input:
|
||||||
await cache_by_id("TOPIC", tpc["id"])
|
await cache_by_id(Topic, tpc["id"])
|
||||||
|
|
||||||
# main topic
|
# main topic
|
||||||
main_topic = shout_input.get("main_topic")
|
main_topic = shout_input.get("main_topic")
|
||||||
|
@ -322,7 +320,7 @@ async def update_shout(_, info, shout_id: int, shout_input=None, publish=False):
|
||||||
# search service indexing
|
# search service indexing
|
||||||
search_service.index(shout_by_id)
|
search_service.index(shout_by_id)
|
||||||
for a in shout_by_id.authors:
|
for a in shout_by_id.authors:
|
||||||
await cache_by_id("AUTHOR", a.id)
|
await cache_by_id(Author, a.id)
|
||||||
|
|
||||||
return {"shout": shout_dict, "error": None}
|
return {"shout": shout_dict, "error": None}
|
||||||
else:
|
else:
|
||||||
|
@ -359,12 +357,12 @@ async def delete_shout(_, info, shout_id: int):
|
||||||
session.add(shout)
|
session.add(shout)
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
for author_id in shout.authors:
|
for author in shout.authors:
|
||||||
reactions_unfollow(author_id, shout_id)
|
reactions_unfollow(author.id, shout_id)
|
||||||
await cache_by_id("AUTHOR", author_id)
|
await cache_by_id(Author, author.id)
|
||||||
|
|
||||||
for topic_id in shout.topics:
|
for topic in shout.topics:
|
||||||
await cache_by_id("TOPIC", topic_id)
|
await cache_by_id(Topic, topic.id)
|
||||||
|
|
||||||
await notify_shout(shout_dict, "delete")
|
await notify_shout(shout_dict, "delete")
|
||||||
return {"error": None}
|
return {"error": None}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user