mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 02:55:58 +01:00 
			
		
		
		
	closes #2356
This commit is contained in:
		| @@ -114,7 +114,7 @@ var db = require('./database'), | |||||||
| 		var tids; | 		var tids; | ||||||
| 		async.waterfall([ | 		async.waterfall([ | ||||||
| 			function(next) { | 			function(next) { | ||||||
| 				Categories.getTopicIds(data.targetUid ? 'cid:' + data.cid + ':uid:' + data.targetUid + ':tid' : 'categories:' + data.cid + ':tid', data.start, data.stop, next); | 				Categories.getTopicIds(data.targetUid ? 'cid:' + data.cid + ':uid:' + data.targetUid + ':tids' : 'cid:' + data.cid + ':tids', data.start, data.stop, next); | ||||||
| 			}, | 			}, | ||||||
| 			function(topicIds, next) { | 			function(topicIds, next) { | ||||||
| 				tids = topicIds; | 				tids = topicIds; | ||||||
| @@ -169,7 +169,7 @@ var db = require('./database'), | |||||||
| 				return callback(err); | 				return callback(err); | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| 			db.sortedSetRevRank('categories:' + cid + ':tid', tid, callback); | 			db.sortedSetRevRank('cid:' + cid + ':tids', tid, callback); | ||||||
| 		}); | 		}); | ||||||
| 	}; | 	}; | ||||||
|  |  | ||||||
| @@ -467,7 +467,7 @@ var db = require('./database'), | |||||||
|  |  | ||||||
| 			async.parallel([ | 			async.parallel([ | ||||||
| 				function(next) { | 				function(next) { | ||||||
| 					db.sortedSetAdd('categories:recent_posts:cid:' + cid, postData.timestamp, postData.pid, next); | 					db.sortedSetAdd('cid:' + cid + ':pids', postData.timestamp, postData.pid, next); | ||||||
| 				}, | 				}, | ||||||
| 				function(next) { | 				function(next) { | ||||||
| 					db.incrObjectField('category:' + cid, 'post_count', next); | 					db.incrObjectField('category:' + cid, 'post_count', next); | ||||||
| @@ -476,7 +476,7 @@ var db = require('./database'), | |||||||
| 					if (parseInt(topicData.pinned, 10) === 1) { | 					if (parseInt(topicData.pinned, 10) === 1) { | ||||||
| 						next(); | 						next(); | ||||||
| 					} else { | 					} else { | ||||||
| 						db.sortedSetAdd('categories:' + cid + ':tid', postData.timestamp, postData.tid, next); | 						db.sortedSetAdd('cid:' + cid + ':tids', postData.timestamp, postData.tid, next); | ||||||
| 					} | 					} | ||||||
| 				} | 				} | ||||||
| 			], callback); | 			], callback); | ||||||
|   | |||||||
| @@ -8,7 +8,7 @@ module.exports = function(Categories) { | |||||||
| 	Categories.getActiveUsers = function(cid, callback) { | 	Categories.getActiveUsers = function(cid, callback) { | ||||||
| 		async.waterfall([ | 		async.waterfall([ | ||||||
| 			function(next) { | 			function(next) { | ||||||
| 				db.getSortedSetRevRange('categories:recent_posts:cid:' + cid, 0, 24, next); | 				db.getSortedSetRevRange('cid:' + cid + ':pids', 0, 24, next); | ||||||
| 			}, | 			}, | ||||||
| 			function(pids, next) { | 			function(pids, next) { | ||||||
| 				var keys = pids.map(function(pid) { | 				var keys = pids.map(function(pid) { | ||||||
|   | |||||||
| @@ -9,7 +9,7 @@ var async = require('async'), | |||||||
| module.exports = function(Categories) { | module.exports = function(Categories) { | ||||||
|  |  | ||||||
| 	Categories.purge = function(cid, callback) { | 	Categories.purge = function(cid, callback) { | ||||||
| 		batch.processSortedSet('categories:' + cid + ':tid', function(tids, next) { | 		batch.processSortedSet('cid:' + cid + ':tids', function(tids, next) { | ||||||
| 			async.eachLimit(tids, 10, function(tid, next) { | 			async.eachLimit(tids, 10, function(tid, next) { | ||||||
| 				threadTools.purge(tid, 0, next); | 				threadTools.purge(tid, 0, next); | ||||||
| 			}, next); | 			}, next); | ||||||
| @@ -27,7 +27,11 @@ module.exports = function(Categories) { | |||||||
| 				db.sortedSetRemove('categories:cid', cid, next); | 				db.sortedSetRemove('categories:cid', cid, next); | ||||||
| 			}, | 			}, | ||||||
| 			function(next) { | 			function(next) { | ||||||
| 				db.deleteAll(['categories:' + cid + ':tid', 'categories:recent_posts:cid:' + cid, 'category:' + cid], next); | 				db.deleteAll([ | ||||||
|  | 					'cid:' + cid + ':tids', | ||||||
|  | 					'cid:' + cid + ':pids', | ||||||
|  | 					'category:' + cid | ||||||
|  | 				], next); | ||||||
| 			} | 			} | ||||||
| 		], callback); | 		], callback); | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -15,7 +15,7 @@ module.exports = function(Categories) { | |||||||
| 			return callback(null, []); | 			return callback(null, []); | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		db.getSortedSetRevRange('categories:recent_posts:cid:' + cid, 0, count - 1, function(err, pids) { | 		db.getSortedSetRevRange('cid:' + cid + ':pids', 0, count - 1, function(err, pids) { | ||||||
| 			if (err || !pids || !pids.length) { | 			if (err || !pids || !pids.length) { | ||||||
| 				return callback(err, []); | 				return callback(err, []); | ||||||
| 			} | 			} | ||||||
| @@ -64,7 +64,7 @@ module.exports = function(Categories) { | |||||||
| 			return callback(null, []); | 			return callback(null, []); | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		db.getSortedSetRevRange('categories:recent_posts:cid:' + category.cid, 0, 0, function(err, pids) { | 		db.getSortedSetRevRange('cid:' + category.cid + ':pids', 0, 0, function(err, pids) { | ||||||
| 			if (err || !Array.isArray(pids) || !pids.length) { | 			if (err || !Array.isArray(pids) || !pids.length) { | ||||||
| 				return callback(err, []); | 				return callback(err, []); | ||||||
| 			} | 			} | ||||||
| @@ -75,10 +75,10 @@ module.exports = function(Categories) { | |||||||
|  |  | ||||||
| 			async.parallel({ | 			async.parallel({ | ||||||
| 				pinnedTids: function(next) { | 				pinnedTids: function(next) { | ||||||
| 					db.getSortedSetRevRangeByScore('categories:' + category.cid + ':tid', 0, -1, Infinity, Date.now(), next); | 					db.getSortedSetRevRangeByScore('cid:' + category.cid + ':tids', 0, -1, Infinity, Date.now(), next); | ||||||
| 				}, | 				}, | ||||||
| 				tids: function(next) { | 				tids: function(next) { | ||||||
| 					db.getSortedSetRevRangeByScore('categories:' + category.cid + ':tid', 0, Math.max(0, count), Date.now(), 0, next); | 					db.getSortedSetRevRangeByScore('cid:' + category.cid + ':tids', 0, Math.max(0, count), Date.now(), 0, next); | ||||||
| 				} | 				} | ||||||
| 			}, function(err, results) { | 			}, function(err, results) { | ||||||
| 				if (err) { | 				if (err) { | ||||||
| @@ -140,10 +140,10 @@ module.exports = function(Categories) { | |||||||
|  |  | ||||||
| 					async.parallel([ | 					async.parallel([ | ||||||
| 						function(next) { | 						function(next) { | ||||||
| 							db.sortedSetRemove('categories:recent_posts:cid:' + oldCid, movePids, next); | 							db.sortedSetRemove('cid:' + oldCid + ':pids', movePids, next); | ||||||
| 						}, | 						}, | ||||||
| 						function(next) { | 						function(next) { | ||||||
| 							db.sortedSetAdd('categories:recent_posts:cid:' + cid, timestamps, movePids, next); | 							db.sortedSetAdd('cid:' + cid + ':pids', timestamps, movePids, next); | ||||||
| 						} | 						} | ||||||
| 					], function(err) { | 					], function(err) { | ||||||
| 						if (err) { | 						if (err) { | ||||||
|   | |||||||
| @@ -87,7 +87,7 @@ module.exports = function(Posts) { | |||||||
| 				return callback(err); | 				return callback(err); | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| 			db.sortedSetRemove('categories:recent_posts:cid:' + cid, pid, callback); | 			db.sortedSetRemove('cid:' + cid + ':pids', pid, callback); | ||||||
| 		}); | 		}); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| @@ -97,7 +97,7 @@ module.exports = function(Posts) { | |||||||
| 				return callback(err); | 				return callback(err); | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| 			db.sortedSetAdd('categories:recent_posts:cid:' + cid, timestamp, pid, callback); | 			db.sortedSetAdd('cid:' + cid + ':pids', timestamp, pid, callback); | ||||||
| 		}); | 		}); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| @@ -180,7 +180,7 @@ module.exports = function(Posts) { | |||||||
| 			} | 			} | ||||||
|  |  | ||||||
| 			var sets = cids.map(function(cid) { | 			var sets = cids.map(function(cid) { | ||||||
| 				return 'categories:recent_posts:cid:' + cid; | 				return 'cid:' + cid + ':pids'; | ||||||
| 			}); | 			}); | ||||||
|  |  | ||||||
| 			db.sortedSetsRemove(sets, pid, callback); | 			db.sortedSetsRemove(sets, pid, callback); | ||||||
|   | |||||||
| @@ -383,7 +383,7 @@ SocketTopics.moveAll = function(socket, data, callback) { | |||||||
| 			return callback(err || new Error('[[error:no-privileges]]')); | 			return callback(err || new Error('[[error:no-privileges]]')); | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		categories.getTopicIds('categories:' + data.currentCid + ':tid', 0, -1, function(err, tids) { | 		categories.getTopicIds('cid:' + data.currentCid + ':tids', 0, -1, function(err, tids) { | ||||||
| 			if (err) { | 			if (err) { | ||||||
| 				return callback(err); | 				return callback(err); | ||||||
| 			} | 			} | ||||||
|   | |||||||
| @@ -163,7 +163,7 @@ var winston = require('winston'), | |||||||
|  |  | ||||||
| 			topics.setTopicField(tid, 'pinned', pin ? 1 : 0); | 			topics.setTopicField(tid, 'pinned', pin ? 1 : 0); | ||||||
| 			topics.getTopicFields(tid, ['cid', 'lastposttime'], function(err, topicData) { | 			topics.getTopicFields(tid, ['cid', 'lastposttime'], function(err, topicData) { | ||||||
| 				db.sortedSetAdd('categories:' + topicData.cid + ':tid', pin ? Math.pow(2, 53) : topicData.lastposttime, tid); | 				db.sortedSetAdd('cid:' + topicData.cid + ':tids', pin ? Math.pow(2, 53) : topicData.lastposttime, tid); | ||||||
| 			}); | 			}); | ||||||
|  |  | ||||||
| 			plugins.fireHook('action:topic.pin', { | 			plugins.fireHook('action:topic.pin', { | ||||||
| @@ -192,11 +192,11 @@ var winston = require('winston'), | |||||||
| 			}, | 			}, | ||||||
| 			function(topicData, next) { | 			function(topicData, next) { | ||||||
| 				topic = topicData; | 				topic = topicData; | ||||||
| 				db.sortedSetRemove('categories:' + topicData.cid + ':tid', tid, next); | 				db.sortedSetRemove('cid:' + topicData.cid + ':tids', tid, next); | ||||||
| 			}, | 			}, | ||||||
| 			function(next) { | 			function(next) { | ||||||
| 				var timestamp = parseInt(topic.pinned, 10) ? Math.pow(2, 53) : topic.lastposttime; | 				var timestamp = parseInt(topic.pinned, 10) ? Math.pow(2, 53) : topic.lastposttime; | ||||||
| 				db.sortedSetAdd('categories:' + cid + ':tid', timestamp, tid, next); | 				db.sortedSetAdd('cid:' + cid + ':tids', timestamp, tid, next); | ||||||
| 			} | 			} | ||||||
| 		], function(err) { | 		], function(err) { | ||||||
| 			if (err) { | 			if (err) { | ||||||
|   | |||||||
| @@ -62,7 +62,11 @@ module.exports = function(Topics) { | |||||||
|  |  | ||||||
| 				async.parallel([ | 				async.parallel([ | ||||||
| 					function(next) { | 					function(next) { | ||||||
| 						db.sortedSetsAdd(['topics:tid', 'categories:' + cid + ':tid', 'cid:' + cid + ':uid:' + uid + ':tid'], timestamp, tid, next); | 						db.sortedSetsAdd([ | ||||||
|  | 							'topics:tid', | ||||||
|  | 							'cid:' + cid + ':tids', | ||||||
|  | 							'cid:' + cid + ':uid:' + uid + ':tids' | ||||||
|  | 						], timestamp, tid, next); | ||||||
| 					}, | 					}, | ||||||
| 					function(next) { | 					function(next) { | ||||||
| 						user.addTopicIdToUser(uid, tid, timestamp, next); | 						user.addTopicIdToUser(uid, tid, timestamp, next); | ||||||
|   | |||||||
| @@ -77,7 +77,11 @@ module.exports = function(Topics) { | |||||||
| 				return callback(err); | 				return callback(err); | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| 			db.sortedSetsRemove(['categories:' + topicData.cid + ':tid', 'uid:' + topicData.uid + ':topics'], tid, callback); | 			db.sortedSetsRemove([ | ||||||
|  | 				'cid:' + topicData.cid + ':tids', | ||||||
|  | 				'cid:' + topicData.cid + ':uid:' + topicData.uid + ':tids', | ||||||
|  | 				'uid:' + topicData.uid + ':topics' | ||||||
|  | 			], tid, callback); | ||||||
| 		}); | 		}); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|   | |||||||
| @@ -19,7 +19,7 @@ var db = require('./database'), | |||||||
| 	schemaDate, thisSchemaDate, | 	schemaDate, thisSchemaDate, | ||||||
|  |  | ||||||
| 	// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema | 	// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema | ||||||
| 	latestSchema = Date.UTC(2014, 10, 6, 18, 30); | 	latestSchema = Date.UTC(2014, 10, 7); | ||||||
|  |  | ||||||
| Upgrade.check = function(callback) { | Upgrade.check = function(callback) { | ||||||
| 	db.get('schemaDate', function(err, value) { | 	db.get('schemaDate', function(err, value) { | ||||||
| @@ -1170,7 +1170,7 @@ Upgrade.upgrade = function(callback) { | |||||||
| 		function(next) { | 		function(next) { | ||||||
| 			thisSchemaDate = Date.UTC(2014, 10, 6, 18, 30); | 			thisSchemaDate = Date.UTC(2014, 10, 6, 18, 30); | ||||||
| 			if (schemaDate < thisSchemaDate) { | 			if (schemaDate < thisSchemaDate) { | ||||||
| 				winston.info('[2014/10/31] Updating topic authorship sorted set'); | 				winston.info('[2014/11/6] Updating topic authorship sorted set'); | ||||||
|  |  | ||||||
| 				async.waterfall([ | 				async.waterfall([ | ||||||
| 					async.apply(db.getObjectField, 'global', 'nextTid'), | 					async.apply(db.getObjectField, 'global', 'nextTid'), | ||||||
| @@ -1201,18 +1201,79 @@ Upgrade.upgrade = function(callback) { | |||||||
| 					} | 					} | ||||||
| 				], function(err) { | 				], function(err) { | ||||||
| 					if (err) { | 					if (err) { | ||||||
| 						winston.error('[2014/10/31] Error encountered while Updating topic authorship sorted set'); | 						winston.error('[2014/11/6] Error encountered while Updating topic authorship sorted set'); | ||||||
| 						return next(err); | 						return next(err); | ||||||
| 					} | 					} | ||||||
| 					winston.info('[2014/10/31] Updating topic authorship sorted set done'); | 					winston.info('[2014/11/6] Updating topic authorship sorted set done'); | ||||||
| 					Upgrade.update(thisSchemaDate, next); | 					Upgrade.update(thisSchemaDate, next); | ||||||
| 				}); | 				}); | ||||||
| 			} else { | 			} else { | ||||||
| 				winston.info('[2014/10/31] Updating topic authorship sorted set skipped'); | 				winston.info('[2014/11/6] Updating topic authorship sorted set skipped'); | ||||||
|  | 				next(); | ||||||
|  | 			} | ||||||
|  | 		}, | ||||||
|  | 		function(next) { | ||||||
|  | 			thisSchemaDate = Date.UTC(2014, 10, 7); | ||||||
|  | 			if (schemaDate < thisSchemaDate) { | ||||||
|  | 				winston.info('[2014/11/7] Renaming sorted set names'); | ||||||
|  |  | ||||||
|  | 				async.waterfall([ | ||||||
|  | 					function(next) { | ||||||
|  | 						async.parallel({ | ||||||
|  | 							cids: function(next) { | ||||||
|  | 								db.getSortedSetRange('categories:cid', 0, -1, next); | ||||||
|  | 							}, | ||||||
|  | 							uids: function(next) { | ||||||
|  | 								db.getSortedSetRange('users:joindate', 0, -1, next); | ||||||
|  | 							} | ||||||
|  | 						}, next); | ||||||
|  | 					}, | ||||||
|  | 					function(results, next) { | ||||||
|  | 						async.eachLimit(results.cids, 50, function(cid, next) { | ||||||
|  | 							async.parallel([ | ||||||
|  | 								function(next) { | ||||||
|  | 									db.exists('categories:' + cid + ':tid', function(err, exists) { | ||||||
|  | 										if (err || !exists) { | ||||||
|  | 											return next(err); | ||||||
|  | 										} | ||||||
|  | 										db.rename('categories:' + cid + ':tid', 'cid:' + cid + ':tids', next); | ||||||
|  | 									}); | ||||||
|  | 								}, | ||||||
|  | 								function(next) { | ||||||
|  | 									db.exists('categories:recent_posts:cid:' + cid, function(err, exists) { | ||||||
|  | 										if (err || !exists) { | ||||||
|  | 											return next(err); | ||||||
|  | 										} | ||||||
|  | 										db.rename('categories:recent_posts:cid:' + cid, 'cid:' + cid + ':pids', next); | ||||||
|  | 									}); | ||||||
|  | 								}, | ||||||
|  | 								function(next) { | ||||||
|  | 									async.eachLimit(results.uids, 50, function(uid, next) { | ||||||
|  | 										db.exists('cid:' + cid + ':uid:' + uid + ':tid', function(err, exists) { | ||||||
|  | 											if (err || !exists) { | ||||||
|  | 												return next(err); | ||||||
|  | 											} | ||||||
|  | 											db.rename('cid:' + cid + ':uid:' + uid + ':tid', 'cid:' + cid + ':uid:' + uid + ':tids', next); | ||||||
|  | 										}); | ||||||
|  | 									}, next); | ||||||
|  | 								} | ||||||
|  | 							], next); | ||||||
|  | 						}, next); | ||||||
|  | 					} | ||||||
|  | 				], function(err) { | ||||||
|  | 					if (err) { | ||||||
|  | 						winston.error('[2014/11/7] Error encountered while renaming sorted sets'); | ||||||
|  | 						return next(err); | ||||||
|  | 					} | ||||||
|  | 					winston.info('[2014/11/7] Renaming sorted sets done'); | ||||||
|  | 					Upgrade.update(thisSchemaDate, next); | ||||||
|  | 				}); | ||||||
|  | 			} else { | ||||||
|  | 				winston.info('[2014/11/7] Renaming sorted sets skipped'); | ||||||
| 				next(); | 				next(); | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 		// Meta.configs.setOnEmpty = function (field, value, callback) { |  | ||||||
| 		// Add new schema updates here | 		// Add new schema updates here | ||||||
| 		// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema IN LINE 22!!! | 		// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema IN LINE 22!!! | ||||||
| 	], function(err) { | 	], function(err) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user