diff --git a/src/activitypub/actors.js b/src/activitypub/actors.js index 6f71f98e2d..628246464e 100644 --- a/src/activitypub/actors.js +++ b/src/activitypub/actors.js @@ -67,6 +67,7 @@ Actors.assert = async (ids, options = {}) => { winston.verbose(`[activitypub/actors] Asserting ${ids.length} actor(s)`); + const urlMap = new Map(); const followersUrlMap = new Map(); const pubKeysMap = new Map(); let actors = await Promise.all(ids.map(async (id) => { @@ -96,7 +97,13 @@ Actors.assert = async (ids, options = {}) => { winston.verbose(`[activitypub/actor.assert] Unable to retrieve post counts for ${actor.id}`); } - // Followers url for backreference + // Save url for backreference + const url = Array.isArray(actor.url) ? actor.url.shift() : actor.url; + if (url && url !== actor.id) { + urlMap.set(url, actor.id); + } + + // Save followers url for backreference if (actor.hasOwnProperty('followers') && activitypub.helpers.isUri(actor.followers)) { followersUrlMap.set(actor.followers, actor.id); } @@ -120,6 +127,9 @@ Actors.assert = async (ids, options = {}) => { memo.push([key, profile], [`${key}:keys`, pubKeysMap.get(profile.uid)]); return memo; }, []); + if (urlMap.size) { + bulkSet.push(['remoteUrl:uid', Object.fromEntries(urlMap)]); + } if (followersUrlMap.size) { bulkSet.push(['followersUrl:uid', Object.fromEntries(followersUrlMap)]); } diff --git a/src/upgrades/4.0.0/remote_user_urls.js b/src/upgrades/4.0.0/remote_user_urls.js index 9c4a1a1924..2b5ee8088a 100644 --- a/src/upgrades/4.0.0/remote_user_urls.js +++ b/src/upgrades/4.0.0/remote_user_urls.js @@ -15,8 +15,9 @@ module.exports = { let actorIds = await db.getSortedSetMembers('usersRemote:lastCrawled'); progress.total = actorIds.length; - const exists = await Promise.all(actorIds.map(async id => await db.isObjectFields(`userRemote:${id}`, ['url', 'followersUrl']))); - actorIds = actorIds.filter((id, idx) => !exists[idx].every(Boolean)); + const existing = await db.getObjectValues('remoteUrl:uid'); + const exists = actorIds.map(actorId => existing.includes(actorId)); + actorIds = actorIds.filter((_, idx) => !exists[idx]); // Increment ones that were already completed progress.incr(progress.total - actorIds.length);