mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-22 16:30:34 +01:00
sortedSetCount fix for +inf/-inf
This commit is contained in:
@@ -204,7 +204,14 @@ module.exports = function(db, module) {
|
|||||||
if (!key) {
|
if (!key) {
|
||||||
return callback();
|
return callback();
|
||||||
}
|
}
|
||||||
db.collection('objects').count({_key: key, score: {$gte: min, $lte: max}}, function(err, count) {
|
var scoreQuery = {};
|
||||||
|
if (min !== '-inf') {
|
||||||
|
scoreQuery.$gte = min;
|
||||||
|
}
|
||||||
|
if (max !== '+inf') {
|
||||||
|
scoreQuery.$lte = max;
|
||||||
|
}
|
||||||
|
db.collection('objects').count({_key: key, score: scoreQuery}, function(err, count) {
|
||||||
callback(err, count ? count : 0);
|
callback(err, count ? count : 0);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -141,7 +141,7 @@ describe('Sorted Set methods', function() {
|
|||||||
|
|
||||||
describe('getSortedSetRevRangeByScoreWithScores()', function() {
|
describe('getSortedSetRevRangeByScoreWithScores()', function() {
|
||||||
it('should get count elements with score between max min sorted by score highest to lowest', function(done) {
|
it('should get count elements with score between max min sorted by score highest to lowest', function(done) {
|
||||||
db.getSortedSetRevRangeByScoreWithScores('sorted2', 0, -1, '+inf', 1, function(err, values) {
|
db.getSortedSetRevRangeByScoreWithScores('sorted2', 0, -1, '+inf', 2, function(err, values) {
|
||||||
assert.equal(err, null);
|
assert.equal(err, null);
|
||||||
assert.equal(arguments.length, 2);
|
assert.equal(arguments.length, 2);
|
||||||
assert.deepEqual(values, [{value: 'value3', score: 3}, {value: 'value2', score: 2}]);
|
assert.deepEqual(values, [{value: 'value3', score: 3}, {value: 'value2', score: 2}]);
|
||||||
|
|||||||
Reference in New Issue
Block a user