mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-30 18:46:01 +01:00
optimize getUnreadByField
only get the most recent 100 notifications dont call UserNotifications.getNotifications which does alot more work, call the db directly
This commit is contained in:
@@ -68,6 +68,7 @@ SocketTopics.enter = function(socket, tid, callback) {
|
|||||||
if (!tid || !socket.uid) {
|
if (!tid || !socket.uid) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SocketTopics.markAsRead(socket, [tid], callback);
|
SocketTopics.markAsRead(socket, [tid], callback);
|
||||||
topics.increaseViewCount(tid);
|
topics.increaseViewCount(tid);
|
||||||
websockets.updateRoomBrowsingText('topic_' + tid);
|
websockets.updateRoomBrowsingText('topic_' + tid);
|
||||||
@@ -77,10 +78,6 @@ SocketTopics.postcount = function(socket, tid, callback) {
|
|||||||
topics.getTopicField(tid, 'postcount', callback);
|
topics.getTopicField(tid, 'postcount', callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketTopics.increaseViewCount = function(socket, tid) {
|
|
||||||
topics.increaseViewCount(tid);
|
|
||||||
};
|
|
||||||
|
|
||||||
SocketTopics.markAsRead = function(socket, tids, callback) {
|
SocketTopics.markAsRead = function(socket, tids, callback) {
|
||||||
if(!Array.isArray(tids) || !socket.uid) {
|
if(!Array.isArray(tids) || !socket.uid) {
|
||||||
return callback(new Error('[[error:invalid-data]]'));
|
return callback(new Error('[[error:invalid-data]]'));
|
||||||
@@ -92,6 +89,7 @@ SocketTopics.markAsRead = function(socket, tids, callback) {
|
|||||||
tids = tids.filter(function(tid) {
|
tids = tids.filter(function(tid) {
|
||||||
return tid && utils.isNumber(tid);
|
return tid && utils.isNumber(tid);
|
||||||
});
|
});
|
||||||
|
|
||||||
topics.markAsRead(tids, socket.uid, function(err) {
|
topics.markAsRead(tids, socket.uid, function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
|
|||||||
@@ -220,7 +220,7 @@ var async = require('async'),
|
|||||||
};
|
};
|
||||||
|
|
||||||
UserNotifications.getUnreadByField = function(uid, field, value, callback) {
|
UserNotifications.getUnreadByField = function(uid, field, value, callback) {
|
||||||
db.getSortedSetRange('uid:' + uid + ':notifications:unread', 0, -1, function(err, nids) {
|
db.getSortedSetRange('uid:' + uid + ':notifications:unread', 0, 99, function(err, nids) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
@@ -229,7 +229,11 @@ var async = require('async'),
|
|||||||
return callback(null, []);
|
return callback(null, []);
|
||||||
}
|
}
|
||||||
|
|
||||||
UserNotifications.getNotifications(nids, uid, function(err, notifications) {
|
var keys = nids.map(function(nid) {
|
||||||
|
return 'notifications:' + nid;
|
||||||
|
});
|
||||||
|
|
||||||
|
db.getObjectsFields(keys, [field], function(err, notifications) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
@@ -246,7 +250,6 @@ var async = require('async'),
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
UserNotifications.sendTopicNotificationToFollowers = function(uid, topicData, postData) {
|
UserNotifications.sendTopicNotificationToFollowers = function(uid, topicData, postData) {
|
||||||
db.getSetMembers('followers:' + uid, function(err, followers) {
|
db.getSetMembers('followers:' + uid, function(err, followers) {
|
||||||
if (err || !Array.isArray(followers) || !followers.length) {
|
if (err || !Array.isArray(followers) || !followers.length) {
|
||||||
|
|||||||
Reference in New Issue
Block a user