mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 02:55:58 +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) { | ||||
| 		return; | ||||
| 	} | ||||
|  | ||||
| 	SocketTopics.markAsRead(socket, [tid], callback); | ||||
| 	topics.increaseViewCount(tid); | ||||
| 	websockets.updateRoomBrowsingText('topic_' + tid); | ||||
| @@ -77,10 +78,6 @@ SocketTopics.postcount = function(socket, tid, callback) { | ||||
| 	topics.getTopicField(tid, 'postcount', callback); | ||||
| }; | ||||
|  | ||||
| SocketTopics.increaseViewCount = function(socket, tid) { | ||||
| 	topics.increaseViewCount(tid); | ||||
| }; | ||||
|  | ||||
| SocketTopics.markAsRead = function(socket, tids, callback) { | ||||
| 	if(!Array.isArray(tids) || !socket.uid) { | ||||
| 		return callback(new Error('[[error:invalid-data]]')); | ||||
| @@ -92,6 +89,7 @@ SocketTopics.markAsRead = function(socket, tids, callback) { | ||||
| 	tids = tids.filter(function(tid) { | ||||
| 		return tid && utils.isNumber(tid); | ||||
| 	}); | ||||
|  | ||||
| 	topics.markAsRead(tids, socket.uid, function(err) { | ||||
| 		if (err) { | ||||
| 			return callback(err); | ||||
|   | ||||
| @@ -220,7 +220,7 @@ var async = require('async'), | ||||
| 	}; | ||||
|  | ||||
| 	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) { | ||||
| 				return callback(err); | ||||
| 			} | ||||
| @@ -229,7 +229,11 @@ var async = require('async'), | ||||
| 				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) { | ||||
| 					return callback(err); | ||||
| 				} | ||||
| @@ -246,7 +250,6 @@ var async = require('async'), | ||||
| 		}); | ||||
| 	}; | ||||
|  | ||||
|  | ||||
| 	UserNotifications.sendTopicNotificationToFollowers = function(uid, topicData, postData) { | ||||
| 		db.getSetMembers('followers:' + uid, function(err, followers) { | ||||
| 			if (err || !Array.isArray(followers) || !followers.length) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user