mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
feat: add null tests for sorted sets
This commit is contained in:
@@ -52,7 +52,8 @@ module.exports = function (module) {
|
||||
return;
|
||||
}
|
||||
const isArrayOfScores = Array.isArray(scores);
|
||||
if (!isArrayOfScores && !utils.isNumber(scores)) {
|
||||
if ((!isArrayOfScores && !utils.isNumber(scores)) ||
|
||||
(isArrayOfScores && scores.map(s => utils.isNumber(s)).includes(false))) {
|
||||
throw new Error('[[error:invalid-score, ' + scores + ']]');
|
||||
}
|
||||
|
||||
@@ -75,6 +76,9 @@ module.exports = function (module) {
|
||||
}
|
||||
var bulk = module.client.collection('objects').initializeUnorderedBulkOp();
|
||||
data.forEach(function (item) {
|
||||
if (!utils.isNumber(item[1])) {
|
||||
throw new Error('[[error:invalid-score, ' + item[1] + ']]');
|
||||
}
|
||||
bulk.find({ _key: item[0], value: String(item[2]) }).upsert().updateOne({ $set: { score: parseFloat(item[1]) } });
|
||||
});
|
||||
await bulk.execute();
|
||||
|
||||
Reference in New Issue
Block a user