Skip to content

Commit

Permalink
Merge pull request #175 from BenLubar/174-remove-fixPostsToPids
Browse files Browse the repository at this point in the history
Remove fixPostsToPids.
  • Loading branch information
akhoury committed Feb 27, 2016
2 parents 39b4150 + 32eb3c8 commit a2ca7b4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 43 deletions.
12 changes: 0 additions & 12 deletions server/data.js
Expand Up @@ -290,18 +290,6 @@ var async = require('async'),
return Data.each('posts:pid', 'post:', iterator, options, callback);
};

Data.eachOrphanedPost = function (iterator, options, callback) {
return Data.each('posts:pid', 'post:', iterator, nodeExtend(true,
{where: {
fields: {
_imported_toPid: {exists: true, ne: ''},
_imported_pid: {exists: true, ne: ''},
pid: {exists: true},
toPid: {exists: false}
}
}}, options), callback);
};

Data.eachImportedUser = function(iterator, options, callback) {
return Data.each('_imported:_users', '_imported_user:', iterator, options, callback);
};
Expand Down
45 changes: 14 additions & 31 deletions server/importer.js
Expand Up @@ -204,7 +204,6 @@ var async = require('async'),
Importer.fixGroupsOwners,
Importer.rebanAndMarkReadForUsers,
Importer.fixTopicTimestampsAndRelockLockedTopics,
Importer.fixPostsToPids,
Importer.restoreConfig,
Importer.disallowGuestsWriteOnAllCategories,
Importer.teardown
Expand Down Expand Up @@ -274,7 +273,6 @@ var async = require('async'),
series.push(Importer.fixGroupsOwners);
series.push(Importer.rebanAndMarkReadForUsers);
series.push(Importer.fixTopicTimestampsAndRelockLockedTopics);
series.push(Importer.fixPostsToPids);
series.push(Importer.restoreConfig);
series.push(Importer.disallowGuestsWriteOnAllCategories);
series.push(Importer.teardown);
Expand Down Expand Up @@ -1669,10 +1667,22 @@ var async = require('async'),
}
cb(null, usr);
});
},
function(cb) {
if (!post._toPid) {
return cb(null, null);
}
Data.getImportedPost(post._toPid, function(err, toPost) {
if (err) {
Importer.warn('getImportedPost: ' + post._toPid + ' err: ' + err);
}
cb(null, toPost);
});
}
], function(err, results) {
var topic = results[0];
var user = results[1] || {uid: 0};
var toPost = results[2] || {pid: null};

if (!topic) {
Importer.warn('[process-count-at: ' + count + '] skipping post:_pid: ' + _pid + ' _tid:' + post._tid + ':uid:' + user.uid + ':_uid:' + post._uid + ' imported: ' + !!topic);
Expand Down Expand Up @@ -1738,7 +1748,8 @@ var async = require('async'),
content: post._content,
timestamp: post._timestamp || startTime,
handle: post._handle || post._guest,
ip: post._ip
ip: post._ip,
toPid: toPost.pid,
}, function(err, postReturn){
if (err) {
Importer.warn('[process-count-at: ' + count + '] skipping post: ' + post._pid + ':tid:' + topic.tid + ':_tid:' + post._tid + ':uid:' + user.uid + ':_uid:' + post._uid + ' ' + err);
Expand Down Expand Up @@ -2242,34 +2253,6 @@ var async = require('async'),
});
};

Importer.fixPostsToPids = function(next) {
var count = 0;
Importer.phase('fixPostsToPidsStart');
Importer.progress(0, 1);

Data.countPosts(function(err, total) {
Data.eachOrphanedPost(function(post, done) {
Importer.progress(count++, total);
if (!post || !post._imported_toPid || !post.pid || post.toPid) {
return done();
}
Data.getImportedPost(post._imported_toPid, function(err, toPost) {
if (err || !toPost) {
return done();
}
db.setObjectField('post:' + post.pid, 'toPid', toPost.pid, done);
});
},
{async: true, eachLimit: EACH_LIMIT_BATCH_SIZE},
function(err) {
if (err) throw err;
Importer.progress(1, 1);
Importer.phase('fixPostsToPidsDone');
next();
});
});
};

Importer.fixGroupsOwners = function(next) {
var count = 0;
Importer.phase('fixGroupsOwnersStart');
Expand Down

0 comments on commit a2ca7b4

Please sign in to comment.