From cfbb8ff8877dae57fe65948e7812f12fce23bf6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Tue, 11 Feb 2025 13:45:38 -0500 Subject: [PATCH] fix: getLocalFollowCounts, show non existing deletes --- src/activitypub/actors.js | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/activitypub/actors.js b/src/activitypub/actors.js index ef4e1497c1..d134d65721 100644 --- a/src/activitypub/actors.js +++ b/src/activitypub/actors.js @@ -2,6 +2,7 @@ const nconf = require('nconf'); const winston = require('winston'); +const _ = require('lodash'); const db = require('../database'); const meta = require('../meta'); @@ -244,12 +245,17 @@ Actors.getLocalFollowCounts = async (actors) => { db.sortedSetsCard(followerKeys), db.sortedSetsCard(followingKeys), ]); - - const results = actors.map((actor, index) => { - if (!validActors.includes(actor)) { + const actorToCounts = _.zipObject(validActors, validActors.map( + (a, idx) => ({ followers: followersCounts[idx], following: followingCounts[idx] }) + )); + const results = actors.map((actor) => { + if (!actorToCounts.hasOwnProperty(actor)) { return { followers: 0, following: 0 }; } - return { followers: followersCounts[index], following: followingCounts[index] }; + return { + followers: actorToCounts[actor].followers, + following: actorToCounts[actor].following, + }; }); return isArray ? results : results[0]; @@ -306,13 +312,12 @@ Actors.prune = async () => { winston.info(`[actors/prune] Found ${uids.length} remote users last crawled more than ${days} days ago`); let deletionCount = 0; - + let deletionCountNonExisting = 0; await batch.processArray(uids, async (uids) => { const exists = await db.exists(uids.map(uid => `userRemote:${uid}`)); const uidsThatExist = uids.filter((uid, idx) => exists[idx]); const uidsThatDontExist = uids.filter((uid, idx) => !exists[idx]); - await db.sortedSetRemove('usersRemote:lastCrawled', uidsThatDontExist); const [postCounts, roomCounts, followCounts] = await Promise.all([ db.sortedSetsCard(uidsThatExist.map(uid => `uid:${uid}:posts`)), @@ -333,10 +338,13 @@ Actors.prune = async () => { } } })); + + deletionCountNonExisting += uidsThatDontExist.length; + await db.sortedSetRemove('usersRemote:lastCrawled', uidsThatDontExist); }, { batch: 50, interval: 1000, }); - winston.info(`[actors/prune] ${deletionCount} remote users pruned.`); + winston.info(`[actors/prune] ${deletionCount} remote users pruned. ${deletionCountNonExisting} does not exist`); };