v1.18.x
Baris Soner Usakli 11 years ago
parent 8efea65e87
commit d6780652ad

@ -256,29 +256,26 @@ var db = require('./database'),
} }
CategoryTools.privileges(cid, uid, function(err, privileges) { CategoryTools.privileges(cid, uid, function(err, privileges) {
if (privileges.read) { if(err) {
db.getSortedSetRevRange('categories:recent_posts:cid:' + cid, 0, count - 1, function(err, pids) { return callback(err);
}
if (!privileges.read) {
return callback(null, []);
}
db.getSortedSetRevRange('categories:recent_posts:cid:' + cid, 0, count - 1, function(err, pids) {
if (err) { if (err) {
winston.err(err);
return callback(err, []); return callback(err, []);
} }
if (pids.length === 0) { if (!pids || !pids.length) {
return callback(null, []); return callback(null, []);
} }
posts.getPostSummaryByPids(pids, true, function(err, postData) { posts.getPostSummaryByPids(pids, true, callback);
if(err) {
return callback(err);
}
callback(null, postData);
}); });
}); });
} else {
callback(null, []);
}
});
}; };
Categories.moveRecentReplies = function(tid, oldCid, cid, callback) { Categories.moveRecentReplies = function(tid, oldCid, cid, callback) {

@ -19,7 +19,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, 1, 2, 16, 0).getTime(); var latestSchema = new Date(2014, 1, 7, 16, 0).getTime();
db.get('schemaDate', function(err, value) { db.get('schemaDate', function(err, value) {
if (parseInt(value, 10) >= latestSchema) { if (parseInt(value, 10) >= latestSchema) {
@ -515,6 +515,52 @@ Upgrade.upgrade = function(callback) {
next(); next();
} }
}, },
function(next) {
thisSchemaDate = new Date(2014, 1, 7, 16, 0).getTime();
if (schemaDate < thisSchemaDate) {
updatesMade = true;
winston.info('[2014/2/7] Updating category recent replies');
db.getListRange('categories:cid', 0, -1, function(err, cids) {
function updateCategory(cid, next) {
db.getSortedSetRevRange('categories:recent_posts:cid:' + cid, 0, - 1, function(err, pids) {
function updatePid(pid, next) {
Posts.getCidByPid(pid, function(err, realCid) {
if(err) {
return next(err);
}
if(parseInt(realCid, 10) !== parseInt(cid, 10)) {
Posts.getPostField(pid, 'timestamp', function(err, timestamp) {
db.sortedSetRemove('categories:recent_posts:cid:' + cid, pid);
db.sortedSetAdd('categories:recent_posts:cid:' + realCid, timestamp, pid);
next();
});
} else {
next();
}
});
}
async.each(pids, updatePid, next);
});
}
if(err) {
return next(err);
}
async.each(cids, updateCategory, next);
});
} else {
winston.info('[2014/2/7] Updating category recent replies -- 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!!!
], function(err) { ], function(err) {

Loading…
Cancel
Save