feat: save remote user urls backreference

This commit is contained in:
Julian Lam
2024-05-24 14:11:06 -04:00
parent 7c79e2310a
commit ff53f3c02c
2 changed files with 14 additions and 3 deletions

View File

@@ -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)]);
}

View File

@@ -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);