diff --git a/migration/tables/content_items.py b/migration/tables/content_items.py index 61791aef..cb90f106 100644 --- a/migration/tables/content_items.py +++ b/migration/tables/content_items.py @@ -291,8 +291,8 @@ async def migrate(entry, storage): # content_item ratings to reactions try: - for content_rating in entry.get("ratings", []): - with local_session() as session: + with local_session() as session: + for content_rating in entry.get("ratings", []): rater = ( session.query(User) .filter(User.oid == content_rating["createdBy"]) @@ -329,12 +329,12 @@ async def migrate(entry, storage): ) reaction.update(reaction_dict) else: - # day = ( - # reaction_dict.get("createdAt") or ts - # ).replace(hour=0, minute=0, second=0, microsecond=0) rea = Reaction.create(**reaction_dict) + session.add(rea) await ReactedStorage.react(rea) # shout_dict['ratings'].append(reaction_dict) + + session.commit() except Exception: raise Exception("[migration] content_item.ratings error: \n%r" % content_rating) diff --git a/resolvers/reactions.py b/resolvers/reactions.py index c1b70251..81c48cb5 100644 --- a/resolvers/reactions.py +++ b/resolvers/reactions.py @@ -64,7 +64,10 @@ async def create_reaction(_, info, inp): # TODO: filter allowed for post reaction kinds - reaction = Reaction.create(**inp) + with local_session() as session: + reaction = Reaction.create(**inp) + session.add(reaction) + session.commit() ReactedStorage.react(reaction) try: reactions_follow(user, inp["shout"], True) @@ -72,7 +75,6 @@ async def create_reaction(_, info, inp): print(f"[resolvers.reactions] error on reactions autofollowing: {e}") reaction.stat = await get_reaction_stat(reaction.id) - return {"reaction": reaction} diff --git a/services/stat/reacted.py b/services/stat/reacted.py index 3f2ab222..cb5a8be9 100644 --- a/services/stat/reacted.py +++ b/services/stat/reacted.py @@ -137,8 +137,8 @@ class ReactedStorage: def init(session): self = ReactedStorage all_reactions = session.query(Reaction).all() - self.modified_shouts = set([r.shout for r in all_reactions]) - print("[stat.reacted] %d shouts with reactions updates" % len(self.modified_shouts)) + self.modified_shouts = list(set([r.shout for r in all_reactions])) + print("[stat.reacted] %d shouts with reactions loaded" % len(self.modified_shouts)) @staticmethod async def recount_changed(session): @@ -149,10 +149,10 @@ class ReactedStorage: siblings = session.query(Reaction).where(Reaction.shout == slug).all() await self.recount(siblings) - print("[stat.reacted] %d shouts with reactions updates" % len(self.modified_shouts)) - print("[stat.reacted] %d topics reacted" % len(self.reacted["topics"].values())) - print("[stat.reacted] %d shouts reacted" % len(self.reacted["shouts"])) - print("[stat.reacted] %d reactions reacted" % len(self.reacted["reactions"])) + print("[stat.reacted] %d shouts" % len(self.modified_shouts)) + print("[stat.reacted] %d topics" % len(self.reacted["topics"].values())) + print("[stat.reacted] %d shouts" % len(self.reacted["shouts"])) + print("[stat.reacted] %d reactions" % len(self.reacted["reactions"])) self.modified_shouts = set([]) @staticmethod