mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 03:55:55 +01:00
optimize topics.markTopicNotificationsRead
let's not call it once for each tid
This commit is contained in:
@@ -220,7 +220,7 @@ define('forum/topic/events', [
|
|||||||
function onNewNotification(data) {
|
function onNewNotification(data) {
|
||||||
var tid = ajaxify.data.tid;
|
var tid = ajaxify.data.tid;
|
||||||
if (data && data.tid && parseInt(data.tid, 10) === parseInt(tid, 10)) {
|
if (data && data.tid && parseInt(data.tid, 10) === parseInt(tid, 10)) {
|
||||||
socket.emit('topics.markTopicNotificationsRead', tid);
|
socket.emit('topics.markTopicNotificationsRead', [tid]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -283,7 +283,7 @@ topicsController.get = function(req, res, callback) {
|
|||||||
}
|
}
|
||||||
if (markedRead) {
|
if (markedRead) {
|
||||||
topics.pushUnreadCount(req.uid);
|
topics.pushUnreadCount(req.uid);
|
||||||
topics.markTopicNotificationsRead(tid, req.uid);
|
topics.markTopicNotificationsRead([tid], req.uid);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,18 +19,17 @@ module.exports = function(SocketTopics) {
|
|||||||
|
|
||||||
topics.pushUnreadCount(socket.uid);
|
topics.pushUnreadCount(socket.uid);
|
||||||
|
|
||||||
for (var i=0; i<tids.length; ++i) {
|
topics.markTopicNotificationsRead(tids, socket.uid);
|
||||||
topics.markTopicNotificationsRead(tids[i], socket.uid);
|
|
||||||
}
|
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketTopics.markTopicNotificationsRead = function(socket, tid, callback) {
|
SocketTopics.markTopicNotificationsRead = function(socket, tids, callback) {
|
||||||
if (!tid || !socket.uid) {
|
if (!Array.isArray(tids) || !socket.uid) {
|
||||||
return callback(new Error('[[error:invalid-data]]'));
|
return callback(new Error('[[error:invalid-data]]'));
|
||||||
}
|
}
|
||||||
topics.markTopicNotificationsRead(tid, socket.uid);
|
topics.markTopicNotificationsRead(tids, socket.uid);
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketTopics.markAllRead = function(socket, data, callback) {
|
SocketTopics.markAllRead = function(socket, data, callback) {
|
||||||
|
|||||||
@@ -279,9 +279,7 @@ module.exports = function(Topics) {
|
|||||||
db.getSortedSetRevRangeByScore('topics:recent', 0, -1, '+inf', Topics.unreadCutoff(), next);
|
db.getSortedSetRevRangeByScore('topics:recent', 0, -1, '+inf', Topics.unreadCutoff(), next);
|
||||||
},
|
},
|
||||||
function (tids, next) {
|
function (tids, next) {
|
||||||
for (var i=0; i<tids.length; ++i) {
|
Topics.markTopicNotificationsRead(tids, uid);
|
||||||
Topics.markTopicNotificationsRead(tids[i], uid);
|
|
||||||
}
|
|
||||||
Topics.markAsRead(tids, uid, next);
|
Topics.markAsRead(tids, uid, next);
|
||||||
},
|
},
|
||||||
function (markedRead, next) {
|
function (markedRead, next) {
|
||||||
@@ -290,17 +288,23 @@ module.exports = function(Topics) {
|
|||||||
], callback);
|
], callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
Topics.markTopicNotificationsRead = function(tid, uid) {
|
Topics.markTopicNotificationsRead = function(tids, uid) {
|
||||||
if (!tid) {
|
if (!Array.isArray(tids) || !tids.length) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
user.notifications.getUnreadByField(uid, 'tid', tid, function(err, nids) {
|
|
||||||
if (err) {
|
async.waterfall([
|
||||||
return winston.error(err.stack);
|
function(next) {
|
||||||
|
user.notifications.getUnreadByField(uid, 'tid', tids, next);
|
||||||
|
},
|
||||||
|
function(nids, next) {
|
||||||
|
notifications.markReadMultiple(nids, uid, next);
|
||||||
}
|
}
|
||||||
notifications.markReadMultiple(nids, uid, function() {
|
], function(err) {
|
||||||
user.notifications.pushCount(uid);
|
if (err) {
|
||||||
});
|
return winston.error(err);
|
||||||
|
}
|
||||||
|
user.notifications.pushCount(uid);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ var privileges = require('../privileges');
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
UserNotifications.getUnreadByField = function(uid, field, value, callback) {
|
UserNotifications.getUnreadByField = function(uid, field, values, callback) {
|
||||||
db.getSortedSetRevRange('uid:' + uid + ':notifications:unread', 0, 99, function(err, nids) {
|
db.getSortedSetRevRange('uid:' + uid + ':notifications:unread', 0, 99, function(err, nids) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
@@ -173,9 +173,9 @@ var privileges = require('../privileges');
|
|||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
value = value ? value.toString() : '';
|
values = values.map(function() { return values.toString(); });
|
||||||
nids = notifications.filter(function(notification) {
|
nids = notifications.filter(function(notification) {
|
||||||
return notification && notification[field] && notification[field].toString() === value;
|
return notification && notification[field] && values.indexOf(notification[field].toString()) !== -1;
|
||||||
}).map(function(notification) {
|
}).map(function(notification) {
|
||||||
return notification.nid;
|
return notification.nid;
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user