mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 19:46:01 +01:00
@@ -334,7 +334,7 @@ var db = require('./database.js'),
|
|||||||
|
|
||||||
Categories.isUserActiveIn = function(cid, uid, callback) {
|
Categories.isUserActiveIn = function(cid, uid, callback) {
|
||||||
|
|
||||||
db.getListRange('uid:' + uid + ':posts', 0, -1, function(err, pids) {
|
db.getSortedSetRange('uid:' + uid + ':posts', 0, -1, function(err, pids) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err, null);
|
return callback(err, null);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,12 +17,12 @@ var winston = require('winston'),
|
|||||||
|
|
||||||
(function(PostTools) {
|
(function(PostTools) {
|
||||||
PostTools.isMain = function(pid, tid, callback) {
|
PostTools.isMain = function(pid, tid, callback) {
|
||||||
db.getListRange('tid:' + tid + ':posts', 0, 0, function(err, pids) {
|
db.getSortedSetRange('tid:' + tid + ':posts', 0, 0, function(err, pids) {
|
||||||
if(err) {
|
if(err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
callback(null, pids[0] === pid);
|
callback(null, parseInt(pids[0], 10) === parseInt(pid, 10));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ var db = require('./database'),
|
|||||||
};
|
};
|
||||||
|
|
||||||
Posts.getPostsByTid = function(tid, start, end, callback) {
|
Posts.getPostsByTid = function(tid, start, end, callback) {
|
||||||
db.getListRange('tid:' + tid + ':posts', start, end, function(err, pids) {
|
db.getSortedSetRange('tid:' + tid + ':posts', start, end, function(err, pids) {
|
||||||
if(err) {
|
if(err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
@@ -325,7 +325,7 @@ var db = require('./database'),
|
|||||||
postData.relativeTime = new Date(parseInt(postData.timestamp,10)).toISOString();
|
postData.relativeTime = new Date(parseInt(postData.timestamp,10)).toISOString();
|
||||||
postData.relativeEditTime = parseInt(postData.edited, 10) !== 0 ? (new Date(parseInt(postData.edited, 10)).toISOString()) : '';
|
postData.relativeEditTime = parseInt(postData.edited, 10) !== 0 ? (new Date(parseInt(postData.edited, 10)).toISOString()) : '';
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
winston.err('invalid time value');
|
require('winston').err('invalid time value');
|
||||||
}
|
}
|
||||||
|
|
||||||
postTools.parse(postData.content, function(err, content) {
|
postTools.parse(postData.content, function(err, content) {
|
||||||
|
|||||||
@@ -292,7 +292,10 @@ var winston = require('winston'),
|
|||||||
}
|
}
|
||||||
|
|
||||||
ThreadTools.getLatestUndeletedPid = function(tid, callback) {
|
ThreadTools.getLatestUndeletedPid = function(tid, callback) {
|
||||||
db.getListRange('tid:' + tid + ':posts', 0, -1, function(err, pids) {
|
db.getSortedSetRange('tid:' + tid + ':posts', 0, -1, function(err, pids) {
|
||||||
|
if(err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
if (pids.length === 0) {
|
if (pids.length === 0) {
|
||||||
return callback(new Error('no-undeleted-pids-found'));
|
return callback(new Error('no-undeleted-pids-found'));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ var async = require('async'),
|
|||||||
nconf = require('nconf'),
|
nconf = require('nconf'),
|
||||||
validator = require('validator'),
|
validator = require('validator'),
|
||||||
S = require('string'),
|
S = require('string'),
|
||||||
|
winston = require('winston'),
|
||||||
|
|
||||||
db = require('./database'),
|
db = require('./database'),
|
||||||
posts = require('./posts'),
|
posts = require('./posts'),
|
||||||
@@ -53,7 +54,7 @@ var async = require('async'),
|
|||||||
}
|
}
|
||||||
db.searchIndex('topic', title, tid);
|
db.searchIndex('topic', title, tid);
|
||||||
|
|
||||||
user.addTopicIdToUser(uid, tid);
|
user.addTopicIdToUser(uid, tid, timestamp);
|
||||||
|
|
||||||
// in future it may be possible to add topics to several categories, so leaving the door open here.
|
// in future it may be possible to add topics to several categories, so leaving the door open here.
|
||||||
db.sortedSetAdd('categories:' + cid + ':tid', timestamp, tid);
|
db.sortedSetAdd('categories:' + cid + ':tid', timestamp, tid);
|
||||||
@@ -111,6 +112,7 @@ var async = require('async'),
|
|||||||
}
|
}
|
||||||
|
|
||||||
Topics.reply(tid, uid, content, function(err, postData) {
|
Topics.reply(tid, uid, content, function(err, postData) {
|
||||||
|
|
||||||
if(err) {
|
if(err) {
|
||||||
return callback(err, null);
|
return callback(err, null);
|
||||||
} else if(!postData) {
|
} else if(!postData) {
|
||||||
@@ -259,26 +261,26 @@ var async = require('async'),
|
|||||||
return callback(new Error('Topic doesn\'t exist'));
|
return callback(new Error('Topic doesn\'t exist'));
|
||||||
}
|
}
|
||||||
|
|
||||||
posts.getPostField(pid, 'tid', function(err, oldTid) {
|
posts.getPostFields(pid, ['tid', 'timestamp'], function(err, postData) {
|
||||||
if(err) {
|
if(err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!oldTid) {
|
if(!postData) {
|
||||||
return callback(new Error('Post doesn\'t exist'));
|
return callback(new Error('Post doesn\'t exist'));
|
||||||
}
|
}
|
||||||
|
|
||||||
Topics.removePostFromTopic(oldTid, pid, function(err) {
|
Topics.removePostFromTopic(postData.tid, pid, function(err) {
|
||||||
if(err) {
|
if(err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
Topics.decreasePostCount(oldTid);
|
Topics.decreasePostCount(postData.tid);
|
||||||
|
|
||||||
posts.setPostField(pid, 'tid', tid);
|
posts.setPostField(pid, 'tid', tid);
|
||||||
|
|
||||||
Topics.increasePostCount(tid);
|
Topics.increasePostCount(tid);
|
||||||
Topics.addPostToTopic(tid, pid, callback);
|
Topics.addPostToTopic(tid, pid, postData.timestamp, callback);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -1041,19 +1043,19 @@ var async = require('async'),
|
|||||||
Topics.onNewPostMade = function(tid, pid, timestamp, callback) {
|
Topics.onNewPostMade = function(tid, pid, timestamp, callback) {
|
||||||
Topics.increasePostCount(tid);
|
Topics.increasePostCount(tid);
|
||||||
Topics.updateTimestamp(tid, timestamp);
|
Topics.updateTimestamp(tid, timestamp);
|
||||||
Topics.addPostToTopic(tid, pid, callback);
|
Topics.addPostToTopic(tid, pid, timestamp, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
Topics.addPostToTopic = function(tid, pid, callback) {
|
Topics.addPostToTopic = function(tid, pid, timestamp, callback) {
|
||||||
db.listAppend('tid:' + tid + ':posts', pid, callback);
|
db.sortedSetAdd('tid:' + tid + ':posts', timestamp, pid, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
Topics.removePostFromTopic = function(tid, pid, callback) {
|
Topics.removePostFromTopic = function(tid, pid, callback) {
|
||||||
db.listRemoveAll('tid:' + tid + ':posts', pid, callback);
|
db.sortedSetRemove('tid:' + tid + ':posts', pid, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
Topics.getPids = function(tid, callback) {
|
Topics.getPids = function(tid, callback) {
|
||||||
db.getListRange('tid:' + tid + ':posts', 0, -1, callback);
|
db.getSortedSetRange('tid:' + tid + ':posts', 0, -1, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
Topics.getUids = function(tid, callback) {
|
Topics.getUids = function(tid, callback) {
|
||||||
|
|||||||
129
src/upgrade.js
129
src/upgrade.js
@@ -6,6 +6,7 @@ var db = require('./database'),
|
|||||||
|
|
||||||
User = require('./user'),
|
User = require('./user'),
|
||||||
Topics = require('./topics'),
|
Topics = require('./topics'),
|
||||||
|
Posts = require('./posts'),
|
||||||
Utils = require('../public/src/utils'),
|
Utils = require('../public/src/utils'),
|
||||||
|
|
||||||
Upgrade = {},
|
Upgrade = {},
|
||||||
@@ -14,7 +15,7 @@ var db = require('./database'),
|
|||||||
|
|
||||||
Upgrade.check = function(callback) {
|
Upgrade.check = function(callback) {
|
||||||
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema
|
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema
|
||||||
var latestSchema = new Date(2014, 0, 5, 14, 5).getTime();
|
var latestSchema = new Date(2014, 0, 7).getTime();
|
||||||
|
|
||||||
db.get('schemaDate', function(err, value) {
|
db.get('schemaDate', function(err, value) {
|
||||||
if (parseInt(value, 10) >= latestSchema) {
|
if (parseInt(value, 10) >= latestSchema) {
|
||||||
@@ -250,6 +251,132 @@ Upgrade.upgrade = function(callback) {
|
|||||||
winston.info('[2014/1/5] Re-slugify usernames (again) skipped');
|
winston.info('[2014/1/5] Re-slugify usernames (again) skipped');
|
||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
function(next) {
|
||||||
|
function upgradeUserPostsTopics(next) {
|
||||||
|
|
||||||
|
function upgradeUser(uid, next) {
|
||||||
|
|
||||||
|
function upgradeUserPosts(next) {
|
||||||
|
|
||||||
|
function addPostToUser(pid) {
|
||||||
|
Posts.getPostField(pid, 'timestamp', function(err, timestamp) {
|
||||||
|
db.sortedSetAdd('uid:' + uid + ':posts', timestamp, pid);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
db.getListRange('uid:' + uid + ':posts', 0, -1, function(err, pids) {
|
||||||
|
if(err) {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!pids || !pids.length) {
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
|
||||||
|
db.delete('uid:' + uid + ':posts', function(err) {
|
||||||
|
for(var i = 0; i< pids.length; ++i) {
|
||||||
|
addPostToUser(pids[i]);
|
||||||
|
}
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function upgradeUserTopics(next) {
|
||||||
|
|
||||||
|
function addTopicToUser(tid) {
|
||||||
|
Topics.getTopicField(tid, 'timestamp', function(err, timestamp) {
|
||||||
|
db.sortedSetAdd('uid:' + uid + ':topics', timestamp, tid);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
db.getListRange('uid:' + uid + ':topics', 0, -1, function(err, tids) {
|
||||||
|
if(err) {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!tids || !tids.length) {
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
|
||||||
|
db.delete('uid:' + uid + ':topics', function(err) {
|
||||||
|
for(var i = 0; i< tids.length; ++i) {
|
||||||
|
addTopicToUser(tids[i]);
|
||||||
|
}
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async.series([upgradeUserPosts, upgradeUserTopics], function(err, result) {
|
||||||
|
next(err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
db.getSortedSetRange('users:joindate', 0, -1, function(err, uids) {
|
||||||
|
if(err) {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
async.each(uids, upgradeUser, function(err, result) {
|
||||||
|
next(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function upgradeTopicPosts(next) {
|
||||||
|
function upgradeTopic(tid, next) {
|
||||||
|
function addPostToTopic(pid) {
|
||||||
|
Posts.getPostField(pid, 'timestamp', function(err, timestamp) {
|
||||||
|
db.sortedSetAdd('tid:' + tid + ':posts', timestamp, pid);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
db.getListRange('tid:' + tid + ':posts', 0, -1, function(err, pids) {
|
||||||
|
if(err) {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!pids || !pids.length) {
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
|
||||||
|
db.delete('tid:' + tid + ':posts', function(err) {
|
||||||
|
for(var i = 0; i< pids.length; ++i) {
|
||||||
|
addPostToTopic(pids[i]);
|
||||||
|
}
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
db.getSetMembers('topics:tid', function(err, tids) {
|
||||||
|
async.each(tids, upgradeTopic, function(err, results) {
|
||||||
|
next(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
thisSchemaDate = new Date(2014, 0, 7).getTime();
|
||||||
|
if (schemaDate < thisSchemaDate) {
|
||||||
|
updatesMade = true;
|
||||||
|
|
||||||
|
async.series([upgradeUserPostsTopics, upgradeTopicPosts], function(err, results) {
|
||||||
|
if(err) {
|
||||||
|
winston.err('Error upgrading '+ err.message);
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
winston.info('[2014/1/7] Updated topic and user posts to sorted set');
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
|
||||||
|
} else {
|
||||||
|
winston.info('[2014/1/7] Update to topic and user posts to sorted set skipped');
|
||||||
|
next();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Add new schema updates here
|
// Add new schema updates here
|
||||||
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema IN LINE 17!!!
|
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema IN LINE 17!!!
|
||||||
|
|||||||
12
src/user.js
12
src/user.js
@@ -454,7 +454,7 @@ var bcrypt = require('bcrypt'),
|
|||||||
};
|
};
|
||||||
|
|
||||||
User.onNewPostMade = function(uid, tid, pid, timestamp) {
|
User.onNewPostMade = function(uid, tid, pid, timestamp) {
|
||||||
User.addPostIdToUser(uid, pid);
|
User.addPostIdToUser(uid, pid, timestamp);
|
||||||
|
|
||||||
User.incrementUserFieldBy(uid, 'postcount', 1, function(err, newpostcount) {
|
User.incrementUserFieldBy(uid, 'postcount', 1, function(err, newpostcount) {
|
||||||
db.sortedSetAdd('users:postcount', newpostcount, uid);
|
db.sortedSetAdd('users:postcount', newpostcount, uid);
|
||||||
@@ -463,16 +463,16 @@ var bcrypt = require('bcrypt'),
|
|||||||
User.setUserField(uid, 'lastposttime', timestamp);
|
User.setUserField(uid, 'lastposttime', timestamp);
|
||||||
};
|
};
|
||||||
|
|
||||||
User.addPostIdToUser = function(uid, pid) {
|
User.addPostIdToUser = function(uid, pid, timestamp) {
|
||||||
db.listPrepend('uid:' + uid + ':posts', pid);
|
db.sortedSetAdd('uid:' + uid + ':posts', timestamp, pid);
|
||||||
};
|
};
|
||||||
|
|
||||||
User.addTopicIdToUser = function(uid, tid) {
|
User.addTopicIdToUser = function(uid, tid, timestamp) {
|
||||||
db.listPrepend('uid:' + uid + ':topics', tid);
|
db.sortedSetAdd('uid:' + uid + ':topics', timestamp, tid);
|
||||||
};
|
};
|
||||||
|
|
||||||
User.getPostIds = function(uid, start, stop, callback) {
|
User.getPostIds = function(uid, start, stop, callback) {
|
||||||
db.getListRange('uid:' + uid + ':posts', start, stop, function(err, pids) {
|
db.getSortedSetRevRange('uid:' + uid + ':posts', start, stop, function(err, pids) {
|
||||||
if(err) {
|
if(err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -905,8 +905,8 @@ websockets.init = function(io) {
|
|||||||
callback({
|
callback({
|
||||||
titleEditable: isMain
|
titleEditable: isMain
|
||||||
});
|
});
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('api:post.privileges', function(pid) {
|
socket.on('api:post.privileges', function(pid) {
|
||||||
|
|||||||
Reference in New Issue
Block a user