minor changes
This commit is contained in:
parent
25cb44b40e
commit
7fb346a41b
|
@ -291,8 +291,8 @@ async def migrate(entry, storage):
|
||||||
|
|
||||||
# content_item ratings to reactions
|
# content_item ratings to reactions
|
||||||
try:
|
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 = (
|
rater = (
|
||||||
session.query(User)
|
session.query(User)
|
||||||
.filter(User.oid == content_rating["createdBy"])
|
.filter(User.oid == content_rating["createdBy"])
|
||||||
|
@ -329,12 +329,12 @@ async def migrate(entry, storage):
|
||||||
)
|
)
|
||||||
reaction.update(reaction_dict)
|
reaction.update(reaction_dict)
|
||||||
else:
|
else:
|
||||||
# day = (
|
|
||||||
# reaction_dict.get("createdAt") or ts
|
|
||||||
# ).replace(hour=0, minute=0, second=0, microsecond=0)
|
|
||||||
rea = Reaction.create(**reaction_dict)
|
rea = Reaction.create(**reaction_dict)
|
||||||
|
session.add(rea)
|
||||||
await ReactedStorage.react(rea)
|
await ReactedStorage.react(rea)
|
||||||
# shout_dict['ratings'].append(reaction_dict)
|
# shout_dict['ratings'].append(reaction_dict)
|
||||||
|
|
||||||
|
session.commit()
|
||||||
except Exception:
|
except Exception:
|
||||||
raise Exception("[migration] content_item.ratings error: \n%r" % content_rating)
|
raise Exception("[migration] content_item.ratings error: \n%r" % content_rating)
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,10 @@ async def create_reaction(_, info, inp):
|
||||||
|
|
||||||
# TODO: filter allowed for post reaction kinds
|
# TODO: filter allowed for post reaction kinds
|
||||||
|
|
||||||
|
with local_session() as session:
|
||||||
reaction = Reaction.create(**inp)
|
reaction = Reaction.create(**inp)
|
||||||
|
session.add(reaction)
|
||||||
|
session.commit()
|
||||||
ReactedStorage.react(reaction)
|
ReactedStorage.react(reaction)
|
||||||
try:
|
try:
|
||||||
reactions_follow(user, inp["shout"], True)
|
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}")
|
print(f"[resolvers.reactions] error on reactions autofollowing: {e}")
|
||||||
|
|
||||||
reaction.stat = await get_reaction_stat(reaction.id)
|
reaction.stat = await get_reaction_stat(reaction.id)
|
||||||
|
|
||||||
return {"reaction": reaction}
|
return {"reaction": reaction}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -137,8 +137,8 @@ class ReactedStorage:
|
||||||
def init(session):
|
def init(session):
|
||||||
self = ReactedStorage
|
self = ReactedStorage
|
||||||
all_reactions = session.query(Reaction).all()
|
all_reactions = session.query(Reaction).all()
|
||||||
self.modified_shouts = set([r.shout for r in all_reactions])
|
self.modified_shouts = list(set([r.shout for r in all_reactions]))
|
||||||
print("[stat.reacted] %d shouts with reactions updates" % len(self.modified_shouts))
|
print("[stat.reacted] %d shouts with reactions loaded" % len(self.modified_shouts))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def recount_changed(session):
|
async def recount_changed(session):
|
||||||
|
@ -149,10 +149,10 @@ class ReactedStorage:
|
||||||
siblings = session.query(Reaction).where(Reaction.shout == slug).all()
|
siblings = session.query(Reaction).where(Reaction.shout == slug).all()
|
||||||
await self.recount(siblings)
|
await self.recount(siblings)
|
||||||
|
|
||||||
print("[stat.reacted] %d shouts with reactions updates" % len(self.modified_shouts))
|
print("[stat.reacted] %d shouts" % len(self.modified_shouts))
|
||||||
print("[stat.reacted] %d topics reacted" % len(self.reacted["topics"].values()))
|
print("[stat.reacted] %d topics" % len(self.reacted["topics"].values()))
|
||||||
print("[stat.reacted] %d shouts reacted" % len(self.reacted["shouts"]))
|
print("[stat.reacted] %d shouts" % len(self.reacted["shouts"]))
|
||||||
print("[stat.reacted] %d reactions reacted" % len(self.reacted["reactions"]))
|
print("[stat.reacted] %d reactions" % len(self.reacted["reactions"]))
|
||||||
self.modified_shouts = set([])
|
self.modified_shouts = set([])
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
Loading…
Reference in New Issue
Block a user