delay write to fix copypad -- bad practice but due to db.set not allowing callback

This commit is contained in:
John McLear 2014-12-29 14:59:22 +01:00
parent 3fe802077c
commit 302ceb665b

View file

@ -461,7 +461,6 @@ Pad.prototype.copy = function copy(destinationID, force, callback) {
// if the pad exists, we should abort, unless forced. // if the pad exists, we should abort, unless forced.
function(callback) function(callback)
{ {
console.log("destinationID", destinationID, force);
padManager.doesPadExists(destinationID, function (err, exists) padManager.doesPadExists(destinationID, function (err, exists)
{ {
if(ERR(err, callback)) return; if(ERR(err, callback)) return;
@ -470,9 +469,9 @@ Pad.prototype.copy = function copy(destinationID, force, callback) {
{ {
if (!force) if (!force)
{ {
console.log("erroring out without force"); console.error("erroring out without force");
callback(new customError("destinationID already exists","apierror")); callback(new customError("destinationID already exists","apierror"));
console.log("erroring out without force - after"); console.error("erroring out without force - after");
return; return;
} }
else // exists and forcing else // exists and forcing
@ -521,12 +520,9 @@ Pad.prototype.copy = function copy(destinationID, force, callback) {
function(callback) function(callback)
{ {
var revHead = _this.head; var revHead = _this.head;
//console.log(revHead);
for(var i=0;i<=revHead;i++) for(var i=0;i<=revHead;i++)
{ {
db.get("pad:"+sourceID+":revs:"+i, function (err, rev) { db.get("pad:"+sourceID+":revs:"+i, function (err, rev) {
//console.log("HERE");
if (ERR(err, callback)) return; if (ERR(err, callback)) return;
db.set("pad:"+destinationID+":revs:"+i, rev); db.set("pad:"+destinationID+":revs:"+i, rev);
}); });
@ -538,10 +534,8 @@ Pad.prototype.copy = function copy(destinationID, force, callback) {
function(callback) function(callback)
{ {
var authorIDs = _this.getAllAuthors(); var authorIDs = _this.getAllAuthors();
authorIDs.forEach(function (authorID) authorIDs.forEach(function (authorID)
{ {
console.log("authors");
authorManager.addPad(authorID, destinationID); authorManager.addPad(authorID, destinationID);
}); });
@ -555,7 +549,9 @@ Pad.prototype.copy = function copy(destinationID, force, callback) {
if(destGroupID) db.setSub("group:" + destGroupID, ["pads", destinationID], 1); if(destGroupID) db.setSub("group:" + destGroupID, ["pads", destinationID], 1);
// Initialize the new pad (will update the listAllPads cache) // Initialize the new pad (will update the listAllPads cache)
padManager.getPad(destinationID, null, callback) setTimeout(function(){
padManager.getPad(destinationID, null, callback) // this runs too early.
},10);
} }
// series // series
], function(err) ], function(err)