mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-03 04:25:55 +01:00
changed sortedSetRangeByScore
This commit is contained in:
@@ -538,21 +538,15 @@
|
|||||||
getSortedSetRange(key, start, stop, -1, callback);
|
getSortedSetRange(key, start, stop, -1, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.getSortedSetRangeByScore = function(args, callback) {
|
module.getSortedSetRangeByScore = function(key, start, count, min, max, callback) {
|
||||||
getSortedSetRangeByScore(args, 1, callback);
|
getSortedSetRangeByScore(key, start, count, min, max, 1, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.getSortedSetRevRangeByScore = function(args, callback) {
|
module.getSortedSetRevRangeByScore = function(key, start, count, max, min, callback) {
|
||||||
getSortedSetRangeByScore(args, -1, callback);
|
getSortedSetRangeByScore(key, start, count, min, max, -1, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
function getSortedSetRangeByScore(args, sort, callback) {
|
function getSortedSetRangeByScore(key, start, count, min, max, sort, callback) {
|
||||||
var key = args[0],
|
|
||||||
max = (args[1] === '+inf') ? Number.MAX_VALUE : args[1],
|
|
||||||
min = args[2],
|
|
||||||
start = args[4],
|
|
||||||
count = args[5];
|
|
||||||
|
|
||||||
if(parseInt(count, 10) === -1) {
|
if(parseInt(count, 10) === -1) {
|
||||||
count = 0;
|
count = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -359,11 +359,13 @@
|
|||||||
redisClient.zrevrange(key, start, stop, callback);
|
redisClient.zrevrange(key, start, stop, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.getSortedSetRangeByScore = function(args, callback) {
|
module.getSortedSetRangeByScore = function(key, start, count, min, max, callback) {
|
||||||
|
var args = [key, min, max, 'LIMIT', start, count];
|
||||||
redisClient.zrangebyscore(args, callback);
|
redisClient.zrangebyscore(args, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.getSortedSetRevRangeByScore = function(args, callback) {
|
module.getSortedSetRevRangeByScore = function(key, start, count, max, min, callback) {
|
||||||
|
var args = [key, max, min, 'LIMIT', start, count];
|
||||||
redisClient.zrevrangebyscore(args, callback);
|
redisClient.zrevrangebyscore(args, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -210,7 +210,7 @@ var db = require('./database'),
|
|||||||
|
|
||||||
var count = parseInt(stop, 10) === -1 ? stop : stop - start + 1;
|
var count = parseInt(stop, 10) === -1 ? stop : stop - start + 1;
|
||||||
|
|
||||||
db.getSortedSetRevRangeByScore(['posts:pid', '+inf', Date.now() - since, 'LIMIT', start, count], function(err, pids) {
|
db.getSortedSetRevRangeByScore('posts:pid', start, count, Infinity, Date.now() - since, function(err, pids) {
|
||||||
if(err) {
|
if(err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ module.exports = function(Topics) {
|
|||||||
|
|
||||||
var count = parseInt(end, 10) === -1 ? end : end - start + 1;
|
var count = parseInt(end, 10) === -1 ? end : end - start + 1;
|
||||||
|
|
||||||
db.getSortedSetRevRangeByScore(['topics:recent', '+inf', Date.now() - since, 'LIMIT', start, count], callback);
|
db.getSortedSetRevRangeByScore('topics:recent', start, count, Infinity, Date.now() - since, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ var async = require('async'),
|
|||||||
UserNotifications.getDailyUnread = function(uid, callback) {
|
UserNotifications.getDailyUnread = function(uid, callback) {
|
||||||
var now = Date.now(),
|
var now = Date.now(),
|
||||||
yesterday = now - (1000*60*60*24); // Approximate, can be more or less depending on time changes, makes no difference really.
|
yesterday = now - (1000*60*60*24); // Approximate, can be more or less depending on time changes, makes no difference really.
|
||||||
db.getSortedSetRangeByScore(['uid:' + uid + ':notifications:unread', yesterday, now], function(err, nids) {
|
db.getSortedSetRangeByScore('uid:' + uid + ':notifications:unread', 0, 20, yesterday, now, function(err, nids) {
|
||||||
async.map(nids, function(nid, next) {
|
async.map(nids, function(nid, next) {
|
||||||
notifications.get(nid, uid, function(notif_data) {
|
notifications.get(nid, uid, function(notif_data) {
|
||||||
next(null, notif_data);
|
next(null, notif_data);
|
||||||
|
|||||||
@@ -127,8 +127,7 @@ describe('Test database', function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getSortedSetRevRangeByScore(callback) {
|
function getSortedSetRevRangeByScore(callback) {
|
||||||
var args = ['sortedSet2', '+inf', 100, 'LIMIT', 0, 10];
|
db.getSortedSetRevRangeByScore('sortedSet2', 0, 10, Infinity, 100, function(err, data) {
|
||||||
db.getSortedSetRevRangeByScore(args, function(err, data) {
|
|
||||||
callback(err, {'getSortedSetRevRangeByScore': data});
|
callback(err, {'getSortedSetRevRangeByScore': data});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user