feat: use getSortedSetsMembers to load followed tids

v1.18.x
Barış Soner Uşaklı 5 years ago
parent ecaa9b76f3
commit 1b9e8928eb

@ -360,15 +360,22 @@ module.exports = function (module) {
if (!Array.isArray(keys) || !keys.length) {
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({
_key: keys.length === 1 ? keys[0] : { $in: keys },
}, { projection: { _id: 0, _key: 1, value: 1 } }).toArray();
_key: arrayOfKeys ? { $in: keys } : keys[0],
}, { projection: projection }).toArray();
var sets = {};
data.forEach(function (set) {
sets[set._key] = sets[set._key] || [];
sets[set._key].push(set.value);
if (!arrayOfKeys) {
return [data.map(item => item.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] || []);

@ -177,9 +177,9 @@ module.exports = function (Topics) {
}
async function getFollowedTids(params) {
const tids = await db.getSortedSetRevRange('uid:' + params.uid + ':followed_tids', 0, -1);
const scores = await db.sortedSetScores('topics:recent', tids);
const data = tids.map((tid, index) => ({ value: tid, score: scores[index] }));
const tids = await db.getSortedSetsMembers(['uid:' + params.uid + ':followed_tids']);
const scores = await db.sortedSetScores('topics:recent', tids[0]);
const data = tids[0].map((tid, index) => ({ value: tid, score: scores[index] }));
return data.filter(item => item.score > params.cutoff);
}

Loading…
Cancel
Save