mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-07 22:45:46 +01:00
faster checkAndReplace
still need a better solution for this uniqueId business but this is better than before.
This commit is contained in:
@@ -135,52 +135,40 @@ var async = require('async'),
|
|||||||
function checkReplace(uniqueId, uid, newNotifObj, callback) {
|
function checkReplace(uniqueId, uid, newNotifObj, callback) {
|
||||||
var replace = false, matched = false;
|
var replace = false, matched = false;
|
||||||
|
|
||||||
|
function checkAndRemove(set, next) {
|
||||||
|
db.getSortedSetRange(set, 0, -1, function(err, nids) {
|
||||||
|
if (err || !nids || !nids.length) {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
var keys = nids.map(function(nid) {
|
||||||
|
return 'notifications:' + nid;
|
||||||
|
});
|
||||||
|
|
||||||
|
db.getObjectsFields(keys, ['uniqueId', 'importance'], function(err, nid_infos) {
|
||||||
|
if (err) {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
nid_infos.forEach(function(nid_info) {
|
||||||
|
if (nid_info && nid_info.uniqueId === uniqueId) {
|
||||||
|
matched = true;
|
||||||
|
if ((nid_info.importance || 5) >= newNotifObj.importance) {
|
||||||
|
replace = true;
|
||||||
|
db.sortedSetRemove(set, nid_info.nid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async.parallel([
|
async.parallel([
|
||||||
function(next) {
|
function(next) {
|
||||||
db.getSortedSetRange('uid:' + uid + ':notifications:unread', 0, -1, function(err, nids) {
|
checkAndRemove('uid:' + uid + ':notifications:unread', next);
|
||||||
if (nids && nids.length > 0) {
|
|
||||||
async.each(nids, function(nid, next) {
|
|
||||||
Notifications.get(nid, uid, function(nid_info) {
|
|
||||||
if (nid_info && nid_info.uniqueId === uniqueId) {
|
|
||||||
matched = true;
|
|
||||||
if ((nid_info.importance || 5) >= newNotifObj.importance) {
|
|
||||||
replace = true;
|
|
||||||
db.sortedSetRemove('uid:' + uid + ':notifications:unread', nid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
next();
|
|
||||||
});
|
|
||||||
}, function(err) {
|
|
||||||
next();
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
next();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
function(next) {
|
function(next) {
|
||||||
db.getSortedSetRange('uid:' + uid + ':notifications:read', 0, -1, function(err, nids) {
|
checkAndRemove('uid:' + uid + ':notifcations:read', next);
|
||||||
if (nids && nids.length > 0) {
|
|
||||||
async.each(nids, function(nid, next) {
|
|
||||||
Notifications.get(nid, uid, function(nid_info) {
|
|
||||||
if (nid_info && nid_info.uniqueId === uniqueId) {
|
|
||||||
matched = true;
|
|
||||||
if ((nid_info.importance || 5) >= newNotifObj.importance) {
|
|
||||||
replace = true;
|
|
||||||
db.sortedSetRemove('uid:' + uid + ':notifications:read', nid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
next();
|
|
||||||
});
|
|
||||||
}, function(err) {
|
|
||||||
next();
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
next();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
], function(err) {
|
], function(err) {
|
||||||
if (!err) {
|
if (!err) {
|
||||||
|
|||||||
Reference in New Issue
Block a user