mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
feat: use getSortedSetsMembers to load followed tids
This commit is contained in:
@@ -360,15 +360,22 @@ module.exports = function (module) {
|
|||||||
if (!Array.isArray(keys) || !keys.length) {
|
if (!Array.isArray(keys) || !keys.length) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
const arrayOfKeys = keys.length > 1;
|
||||||
|
const projection = { _id: 0, value: 1 };
|
||||||
|
if (arrayOfKeys) {
|
||||||
|
projection._key = 1;
|
||||||
|
}
|
||||||
const data = await module.client.collection('objects').find({
|
const data = await module.client.collection('objects').find({
|
||||||
_key: keys.length === 1 ? keys[0] : { $in: keys },
|
_key: arrayOfKeys ? { $in: keys } : keys[0],
|
||||||
}, { projection: { _id: 0, _key: 1, value: 1 } }).toArray();
|
}, { projection: projection }).toArray();
|
||||||
|
|
||||||
var sets = {};
|
if (!arrayOfKeys) {
|
||||||
data.forEach(function (set) {
|
return [data.map(item => item.value)];
|
||||||
sets[set._key] = sets[set._key] || [];
|
}
|
||||||
sets[set._key].push(set.value);
|
const sets = {};
|
||||||
|
data.forEach(function (item) {
|
||||||
|
sets[item._key] = sets[item._key] || [];
|
||||||
|
sets[item._key].push(item.value);
|
||||||
});
|
});
|
||||||
|
|
||||||
return keys.map(k => sets[k] || []);
|
return keys.map(k => sets[k] || []);
|
||||||
|
|||||||
@@ -177,9 +177,9 @@ module.exports = function (Topics) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function getFollowedTids(params) {
|
async function getFollowedTids(params) {
|
||||||
const tids = await db.getSortedSetRevRange('uid:' + params.uid + ':followed_tids', 0, -1);
|
const tids = await db.getSortedSetsMembers(['uid:' + params.uid + ':followed_tids']);
|
||||||
const scores = await db.sortedSetScores('topics:recent', tids);
|
const scores = await db.sortedSetScores('topics:recent', tids[0]);
|
||||||
const data = tids.map((tid, index) => ({ value: tid, score: scores[index] }));
|
const data = tids[0].map((tid, index) => ({ value: tid, score: scores[index] }));
|
||||||
return data.filter(item => item.score > params.cutoff);
|
return data.filter(item => item.score > params.cutoff);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user