mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-28 17:46:16 +01:00
fix: store remote followed users count separately from local
This commit is contained in:
@@ -132,8 +132,10 @@ Controller.follow = async (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
await db.sortedSetAdd(`followingRemote:${req.uid}`, now, objectId);
|
await Promise.all([
|
||||||
await recountFollowing(req.uid);
|
db.sortedSetAdd(`followingRemote:${req.uid}`, now, objectId),
|
||||||
|
db.incrObjectField(`user:${req.uid}`, 'followingRemoteCount'),
|
||||||
|
]);
|
||||||
|
|
||||||
helpers.formatApiResponse(200, res);
|
helpers.formatApiResponse(200, res);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -152,19 +154,13 @@ Controller.unfollow = async (req, res) => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
await db.sortedSetRemove(`followingRemote:${req.uid}`, objectId);
|
await Promise.all([
|
||||||
await recountFollowing(req.uid);
|
db.sortedSetRemove(`followingRemote:${req.uid}`, objectId),
|
||||||
|
db.decrObjectField(`user:${req.uid}`, 'followingRemoteCount'),
|
||||||
|
]);
|
||||||
|
|
||||||
helpers.formatApiResponse(200, res);
|
helpers.formatApiResponse(200, res);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
helpers.formatApiResponse(400, res, e);
|
helpers.formatApiResponse(400, res, e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
async function recountFollowing(uid) {
|
|
||||||
const [followingCount, followingRemoteCount] = await Promise.all([
|
|
||||||
db.sortedSetCard(`following:${uid}`),
|
|
||||||
db.sortedSetCard(`followingRemote:${uid}`),
|
|
||||||
]);
|
|
||||||
await user.setUserField(uid, 'followingCount', followingCount + followingRemoteCount);
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user