mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-02-01 04:09:51 +01:00
removed couple RDB.multis
This commit is contained in:
@@ -439,6 +439,20 @@
|
||||
});
|
||||
}
|
||||
|
||||
module.sortedSetRank = function(key, value, callback) {
|
||||
module.getSortedSetRange(key, 0, -1, function(err, result) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
var rank = result.indexOf(value);
|
||||
if(rank === -1) {
|
||||
return callback(null, null);
|
||||
}
|
||||
|
||||
callback(null, rank);
|
||||
});
|
||||
}
|
||||
|
||||
// lists
|
||||
module.listPrepend = function(key, value, callback) {
|
||||
module.isObjectField(key, 'array', function(err, exists) {
|
||||
@@ -471,6 +485,26 @@
|
||||
});
|
||||
}
|
||||
|
||||
module.listRemoveLast = function(key, callback) {
|
||||
module.getListRange(key, -1, 0, function(err, value) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
db.collection('objects').update({_key: key }, { $pop: { array: 1 } }, function(err, result) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if(value && value.length) {
|
||||
callback(err, value[0]);
|
||||
} else {
|
||||
callback(err, null);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
module.getListRange = function(key, start, stop, callback) {
|
||||
|
||||
if(stop === -1) {
|
||||
|
||||
@@ -291,6 +291,10 @@
|
||||
redisClient.zcount(key, min, max, callback);
|
||||
}
|
||||
|
||||
module.sortedSetRank = function(key, value, callback) {
|
||||
redisClient.zrank(key, value, callback);
|
||||
}
|
||||
|
||||
// lists
|
||||
module.listPrepend = function(key, value, callback) {
|
||||
redisClient.lpush(key, value, callback);
|
||||
@@ -300,11 +304,16 @@
|
||||
redisClient.rpush(key, value, callback);
|
||||
}
|
||||
|
||||
module.listRemoveLast = function(key, callback) {
|
||||
redisClient.rpop(key, callback);
|
||||
}
|
||||
|
||||
module.getListRange = function(key, start, stop, callback) {
|
||||
redisClient.lrange(key, start, stop, callback);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}(exports));
|
||||
|
||||
|
||||
@@ -18,28 +18,22 @@ var async = require('async'),
|
||||
};
|
||||
|
||||
Notifications.get = function(nid, uid, callback) {
|
||||
RDB.multi()
|
||||
.hmget('notifications:' + nid, 'text', 'score', 'path', 'datetime', 'uniqueId')
|
||||
.zrank('uid:' + uid + ':notifications:read', nid)
|
||||
.exists('notifications:' + nid)
|
||||
.exec(function(err, results) {
|
||||
var notification = results[0],
|
||||
readIdx = results[1];
|
||||
|
||||
if (!results[2]) {
|
||||
return callback(null);
|
||||
}
|
||||
db.exists('nofitications:' + nid, function(err, exists) {
|
||||
|
||||
callback({
|
||||
nid: nid,
|
||||
text: notification[0],
|
||||
score: notification[1],
|
||||
path: notification[2],
|
||||
datetime: notification[3],
|
||||
uniqueId: notification[4],
|
||||
read: readIdx !== null ? true : false
|
||||
if(!exists) {
|
||||
return callback(null);
|
||||
}
|
||||
|
||||
db.sortedSetRank('uid:' + uid + ':notifications:read', nid, function(err, rank) {
|
||||
|
||||
db.getObjectFields('notifications:' + nid, ['nid', 'text', 'score', 'path', 'datetime', 'uniqueId'], function(err, notification) {
|
||||
|
||||
notification.read = rank !== null ? true:false;
|
||||
callback(notification);
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Notifications.create = function(text, path, uniqueId, callback) {
|
||||
|
||||
@@ -197,8 +197,17 @@ var DebugRoute = function(app) {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function listRemoveLast(callback) {
|
||||
db.listRemoveLast('myList5', function(err, data) {
|
||||
console.log('listRemoveLast return', data);
|
||||
callback(err, {'listRemoveLast': data});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function getListRange(callback) {
|
||||
db.getListRange('myList5', 0, 5, function(err, data) {
|
||||
db.getListRange('myList5', 0, -1, function(err, data) {
|
||||
console.log('getListRange return', data);
|
||||
callback(err, {'getListRange': data});
|
||||
});
|
||||
@@ -306,8 +315,10 @@ var DebugRoute = function(app) {
|
||||
];
|
||||
|
||||
var listTasks = [
|
||||
listAppend,
|
||||
listPrepend,
|
||||
//listAppend,
|
||||
//listPrepend,
|
||||
getListRange,
|
||||
listRemoveLast,
|
||||
getListRange
|
||||
];
|
||||
|
||||
@@ -331,7 +342,7 @@ var DebugRoute = function(app) {
|
||||
isMemberOfSets
|
||||
];
|
||||
|
||||
require('async').series(setTasks, function(err, results) {
|
||||
require('async').series(listTasks, function(err, results) {
|
||||
if(err) {
|
||||
console.log(err);
|
||||
res.send(err.message);
|
||||
|
||||
15
src/user.js
15
src/user.js
@@ -1005,14 +1005,13 @@ var bcrypt = require('bcrypt'),
|
||||
before = new Date(parseInt(before, 10));
|
||||
}
|
||||
|
||||
// TODO : figure out how to do this with dbal
|
||||
RDB.multi()
|
||||
.zrevrangebyscore('uid:' + uid + ':notifications:read', before ? before.getTime(): now.getTime(), -Infinity, 'LIMIT', 0, limit)
|
||||
.zrevrangebyscore('uid:' + uid + ':notifications:unread', before ? before.getTime(): now.getTime(), -Infinity, 'LIMIT', 0, limit)
|
||||
.exec(function(err, results) {
|
||||
// Merge the read and unread notifications
|
||||
var nids = results[0].concat(results[1]);
|
||||
var args1 = ['uid:' + uid + ':notifications:read', before ? before.getTime(): now.getTime(), -Infinity, 'LIMIT', 0, limit];
|
||||
var args2 = ['uid:' + uid + ':notifications:unread', before ? before.getTime(): now.getTime(), -Infinity, 'LIMIT', 0, limit];
|
||||
|
||||
db.getSortedSetRevRangeByScore(args1, function(err, results1) {
|
||||
db.getSortedSetRevRangeByScore(args2, function(err, results2) {
|
||||
|
||||
var nids = results1.concat(results2);
|
||||
async.map(nids, function(nid, next) {
|
||||
notifications.get(nid, uid, function(notif_data) {
|
||||
next(null, notif_data);
|
||||
@@ -1032,6 +1031,8 @@ var bcrypt = require('bcrypt'),
|
||||
callback(err, notifs);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
},
|
||||
getUnreadCount: function(uid, callback) {
|
||||
db.sortedSetCount('uid:' + uid + ':notifications:unread', 0, 10, callback);
|
||||
|
||||
@@ -62,9 +62,11 @@ describe('Categories', function() {
|
||||
});
|
||||
|
||||
after(function() {
|
||||
// TODO : replace with dbal
|
||||
RDB.multi()
|
||||
.del('category:'+categoryObj.cid)
|
||||
.rpop('categories:cid')
|
||||
.exec();
|
||||
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user