Archived
1
0

fix up lynxchan migrate script such that it exits

This commit is contained in:
Jeff Becker 2016-02-08 14:09:30 -05:00
parent 37df9ef131
commit 6eb42d4cf7
No known key found for this signature in database
GPG Key ID: AB950234D6EA286B

View File

@ -28,8 +28,15 @@ var makeGroupName = function(board) {
// call function for each op on a board // call function for each op on a board
var foreachOpsOnBoard = function(db, board, callback) { var foreachOpsOnBoard = function(db, board, callback) {
var cur = db.collection("threads").find({boardUri: board}); var cur = db.collection("threads").find({boardUri: board});
var ops = [];
cur.each(function(err, doc) { cur.each(function(err, doc) {
callback(doc); if (doc) {
ops.push(doc)
} else {
for (var idx = 0 ; ops.length > idx ; idx ++ ) {
callback(op[idx]);
}
}
}); });
} }
@ -42,19 +49,32 @@ var foreachReplyForOP = function(db, op, callback) {
}, function(msgid) { }, function(msgid) {
// we don't has got it // we don't has got it
var cur = db.collection("posts").find({ threadId: op.threadId}); var cur = db.collection("posts").find({ threadId: op.threadId});
var repls = [];
cur.each(function(err, doc) { cur.each(function(err, doc) {
callback(doc); if (doc) {
repls.push(doc)
} else {
for (var idx = 0 ; repls.length > idx ; idx ++ ) {
callback(repls[idx]);
}
}
}); });
}); });
} }
// find all boards in memegod // find all boards in memegod
// call callback for each board // call callback for each board
var foreachBoard = function(db, callback) { var foreachBoard = function(db, callback, done) {
var cursor = db.collection('boards').find(); var cursor = db.collection('boards').find();
var boards = [];
cursor.each(function(err, doc) { cursor.each(function(err, doc) {
if (doc) { if (doc) {
callback(doc) boards.push(doc)
} else {
for (var idx = 0 ; boards.length > idx ; idx ++ ) {
callback(boards[idx]);
}
done(db);
} }
}); });
}; };
@ -172,7 +192,6 @@ var putBoard = function(db, board) {
}); });
} }
}); });
}); });
}); });
}); });
@ -183,7 +202,8 @@ memegodClient.connect(url, function(err, db) {
foreachBoard(db, function(board) { foreachBoard(db, function(board) {
console.log("updating "+board.boardUri); console.log("updating "+board.boardUri);
putBoard(db, board); putBoard(db, board);
}); }, function(db) {
console.log("the meme god has spoken"); console.log("the meme god has spoken");
db.close(); db.close();
}); });
});