Tweak/fix migration

This commit is contained in:
Thomas Sileo 2019-07-16 21:25:04 +02:00
parent 974acabd19
commit 622b39fc26

View file

@ -5,12 +5,12 @@ from urllib.parse import urlparse
from little_boxes import activitypub as ap from little_boxes import activitypub as ap
import activitypub
from config import ID
from utils.migrations import DB from utils.migrations import DB
from utils.migrations import Migration from utils.migrations import Migration
from utils.migrations import logger from utils.migrations import logger
from utils.migrations import perform # noqa: just here for export from utils.migrations import perform # noqa: just here for export
from config import ID
import activitypub
back = activitypub.MicroblogPubBackend() back = activitypub.MicroblogPubBackend()
ap.use_backend(back) ap.use_backend(back)
@ -119,6 +119,7 @@ class _2_FollowMigration(Migration):
def migrate(self) -> None: def migrate(self) -> None:
actor_cache: Dict[str, Dict[str, Any]] = {} actor_cache: Dict[str, Dict[str, Any]] = {}
for data in DB.activities.find({"type": ap.ActivityType.FOLLOW.value}): for data in DB.activities.find({"type": ap.ActivityType.FOLLOW.value}):
try:
if data["meta"]["actor_id"] == ID: if data["meta"]["actor_id"] == ID:
# It's a "following" # It's a "following"
actor = actor_cache.get(data["meta"]["object_id"]) actor = actor_cache.get(data["meta"]["object_id"])
@ -150,3 +151,5 @@ class _2_FollowMigration(Migration):
DB.activities.update_one( DB.activities.update_one(
{"_id": data["_id"]}, {"$set": {"meta.actor": actor}} {"_id": data["_id"]}, {"$set": {"meta.actor": actor}}
) )
except Exception:
logger.exception("failed to process actor {data!r}")