Fix the migration

This commit is contained in:
Thomas Sileo 2018-07-01 11:05:33 +02:00
parent 4e7fb005fa
commit 3bf77b2e82

40
app.py
View file

@ -464,27 +464,27 @@ def tmp_migrate():
@app.route("/migration1_step2") @app.route("/migration1_step2")
@login_required @login_required
def tmp_migrate2(): def tmp_migrate2():
# Remove buggy OStatus announce
DB.activities.remove({"activity.object": {"$regex": f"^tag:"}, "type": ActivityType.ANNOUNCE.value})
# Cache the object
for activity in DB.activities.find(): for activity in DB.activities.find():
try: if (
if ( activity["box"] == Box.OUTBOX.value
activity["box"] == Box.OUTBOX.value and activity["type"] == ActivityType.LIKE.value
and activity["type"] == ActivityType.LIKE.value ):
): like = ap.parse_activity(activity["activity"])
like = ap.parse_activity(activity["activity"]) obj = like.get_object()
obj = like.get_object() DB.activities.update_one(
DB.activities.update_one( {"remote_id": like.id},
{"remote_id": like.id}, {"$set": {"meta.object": obj.to_dict(embed=True)}},
{"$set": {"meta.object": obj.to_dict(embed=True)}}, )
) elif activity["type"] == ActivityType.ANNOUNCE.value:
elif activity["type"] == ActivityType.ANNOUNCE.value: announce = ap.parse_activity(activity["activity"])
announce = ap.parse_activity(activity["activity"]) obj = announce.get_object()
obj = announce.get_object() DB.activities.update_one(
DB.activities.update_one( {"remote_id": announce.id},
{"remote_id": announce.id}, {"$set": {"meta.object": obj.to_dict(embed=True)}},
{"$set": {"meta.object": obj.to_dict(embed=True)}}, )
)
except Exception:
pass
return "Done" return "Done"