mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 19:15:58 +01:00 
			
		
		
		
	optimize privileges and assorted fixes.
* new methods privileges.categories.filter privileges.topics.filter privileges.posts.filter they take a list of ids and a privilege, and return the filtered list of ids, faster than doing async.filter and calling the db for each id. * remove event listeners on recent page before adding * group.exists works for both single group names and arrays * helpers.allowedTo works for both a single cid and an array of cids * moved filter:topic.post hook right before topic creation. * moved filter:topic.reply hook right before topic reply.
This commit is contained in:
		
							
								
								
									
										22
									
								
								src/posts.js
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								src/posts.js
									
									
									
									
									
								
							| @@ -178,11 +178,14 @@ var async = require('async'), | ||||
| 				return callback(err); | ||||
| 			} | ||||
|  | ||||
| 			async.filter(pids, function(pid, next) { | ||||
| 				privileges.posts.can('read', pid, uid, function(err, canRead) { | ||||
| 					next(!err && canRead); | ||||
| 				}); | ||||
| 			}, function(pids) { | ||||
| 			if (!Array.isArray(pids) || !pids.length) { | ||||
| 				return callback(null, []); | ||||
| 			} | ||||
|  | ||||
| 			privileges.posts.filter('read', pids, uid, function(err, pids) { | ||||
| 				if (err) { | ||||
| 					return callback(err); | ||||
| 				} | ||||
| 				Posts.getPostSummaryByPids(pids, {stripTags: true}, callback); | ||||
| 			}); | ||||
| 		}); | ||||
| @@ -487,11 +490,10 @@ var async = require('async'), | ||||
| 				return callback(err); | ||||
| 			} | ||||
|  | ||||
| 			async.filter(pids, function(pid, next) { | ||||
| 				privileges.posts.can('read', pid, callerUid, function(err, canRead) { | ||||
| 					next(!err && canRead); | ||||
| 				}); | ||||
| 			}, function(pids) { | ||||
| 			privileges.posts.filter('read', pids, callerUid, function(err, pids) { | ||||
| 				if (err) { | ||||
| 					return callback(err); | ||||
| 				} | ||||
| 				getPostsFromSet('uid:' + uid + ':posts', pids, callback); | ||||
| 			}); | ||||
| 		}); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user