mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 02:55:58 +01:00 
			
		
		
		
	changed sortedSetRangeByScore
This commit is contained in:
		| @@ -538,21 +538,15 @@ | ||||
| 		getSortedSetRange(key, start, stop, -1, callback); | ||||
| 	}; | ||||
|  | ||||
| 	module.getSortedSetRangeByScore = function(args, callback) { | ||||
| 		getSortedSetRangeByScore(args, 1, callback); | ||||
| 	module.getSortedSetRangeByScore = function(key, start, count, min, max, callback) { | ||||
| 		getSortedSetRangeByScore(key, start, count, min, max, 1, callback); | ||||
| 	}; | ||||
|  | ||||
| 	module.getSortedSetRevRangeByScore = function(args, callback) { | ||||
| 		getSortedSetRangeByScore(args, -1, callback); | ||||
| 	module.getSortedSetRevRangeByScore = function(key, start, count, max, min, callback) { | ||||
| 		getSortedSetRangeByScore(key, start, count, min, max, -1, callback); | ||||
| 	}; | ||||
|  | ||||
| 	function getSortedSetRangeByScore(args, sort, callback) { | ||||
| 		var key = args[0], | ||||
| 			max = (args[1] === '+inf') ? Number.MAX_VALUE : args[1], | ||||
| 			min = args[2], | ||||
| 			start = args[4], | ||||
| 			count = args[5]; | ||||
|  | ||||
| 	function getSortedSetRangeByScore(key, start, count, min, max, sort, callback) { | ||||
| 		if(parseInt(count, 10) === -1) { | ||||
| 			count = 0; | ||||
| 		} | ||||
|   | ||||
| @@ -359,11 +359,13 @@ | ||||
| 		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); | ||||
| 	}; | ||||
|  | ||||
| 	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); | ||||
| 	}; | ||||
|  | ||||
|   | ||||
| @@ -210,7 +210,7 @@ var db = require('./database'), | ||||
|  | ||||
| 		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) { | ||||
| 				return callback(err); | ||||
| 			} | ||||
|   | ||||
| @@ -30,7 +30,7 @@ module.exports = function(Topics) { | ||||
|  | ||||
| 		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) { | ||||
| 		var	now = Date.now(), | ||||
| 			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) { | ||||
| 				notifications.get(nid, uid, function(notif_data) { | ||||
| 					next(null, notif_data); | ||||
|   | ||||
| @@ -127,8 +127,7 @@ describe('Test database', function() { | ||||
| 		} | ||||
|  | ||||
| 		function getSortedSetRevRangeByScore(callback) { | ||||
| 			var args = ['sortedSet2', '+inf', 100, 'LIMIT', 0, 10]; | ||||
| 			db.getSortedSetRevRangeByScore(args, function(err, data) { | ||||
| 			db.getSortedSetRevRangeByScore('sortedSet2', 0, 10, Infinity, 100, function(err, data) { | ||||
| 				callback(err, {'getSortedSetRevRangeByScore': data}); | ||||
| 			}); | ||||
| 		} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user