Don't write metadata updates to the log if it doesn't change the value
This commit is contained in:
@@ -28,10 +28,14 @@ commands.ADD_OWNERS = function (meta, args) {
|
|||||||
throw new Error("METADATA_NONSENSE_OWNERS");
|
throw new Error("METADATA_NONSENSE_OWNERS");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var changed = false;
|
||||||
args.forEach(function (owner) {
|
args.forEach(function (owner) {
|
||||||
if (meta.owners.indexOf(owner) >= 0) { return; }
|
if (meta.owners.indexOf(owner) >= 0) { return; }
|
||||||
meta.owners.push(owner);
|
meta.owners.push(owner);
|
||||||
|
changed = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return changed;
|
||||||
};
|
};
|
||||||
|
|
||||||
// ["RM_OWNERS", ["CrufexqXcY-z+eKJlEbNELVy5Sb7E-EAAEFI8GnEtZ0="], 1561623439989]
|
// ["RM_OWNERS", ["CrufexqXcY-z+eKJlEbNELVy5Sb7E-EAAEFI8GnEtZ0="], 1561623439989]
|
||||||
@@ -45,13 +49,17 @@ commands.RM_OWNERS = function (meta, args) {
|
|||||||
throw new Error("METADATA_NONSENSE_OWNERS");
|
throw new Error("METADATA_NONSENSE_OWNERS");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var changed = false;
|
||||||
// remove owners one by one
|
// remove owners one by one
|
||||||
// we assume there are no duplicates
|
// we assume there are no duplicates
|
||||||
args.forEach(function (owner) {
|
args.forEach(function (owner) {
|
||||||
var index = meta.owners.indexOf(owner);
|
var index = meta.owners.indexOf(owner);
|
||||||
if (index < 0) { return; }
|
if (index < 0) { return; }
|
||||||
meta.owners.splice(index, 1);
|
meta.owners.splice(index, 1);
|
||||||
|
changed = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return changed;
|
||||||
};
|
};
|
||||||
|
|
||||||
// ["ADD_PENDING_OWNERS", ["7eEqelGso3EBr5jHlei6av4r9w2B9XZiGGwA1EgZ-5I="], 1561623438989]
|
// ["ADD_PENDING_OWNERS", ["7eEqelGso3EBr5jHlei6av4r9w2B9XZiGGwA1EgZ-5I="], 1561623438989]
|
||||||
@@ -67,16 +75,20 @@ commands.ADD_PENDING_OWNERS = function (meta, args) {
|
|||||||
throw new Error("METADATA_NONSENSE_PENDING_OWNERS");
|
throw new Error("METADATA_NONSENSE_PENDING_OWNERS");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var changed = false;
|
||||||
// Add pending_owners array if it doesn't exist
|
// Add pending_owners array if it doesn't exist
|
||||||
if (!meta.pending_owners) {
|
if (!meta.pending_owners) {
|
||||||
meta.pending_owners = deduplicate(args);
|
meta.pending_owners = deduplicate(args);
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
// or fill it
|
// or fill it
|
||||||
args.forEach(function (owner) {
|
args.forEach(function (owner) {
|
||||||
if (meta.pending_owners.indexOf(owner) >= 0) { return; }
|
if (meta.pending_owners.indexOf(owner) >= 0) { return; }
|
||||||
meta.pending_owners.push(owner);
|
meta.pending_owners.push(owner);
|
||||||
|
changed = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return changed;
|
||||||
};
|
};
|
||||||
|
|
||||||
// ["RM_PENDING_OWNERS", ["CrufexqXcY-z+eKJlEbNELVy5Sb7E-EAAEFI8GnEtZ0="], 1561623439989]
|
// ["RM_PENDING_OWNERS", ["CrufexqXcY-z+eKJlEbNELVy5Sb7E-EAAEFI8GnEtZ0="], 1561623439989]
|
||||||
@@ -90,13 +102,17 @@ commands.RM_PENDING_OWNERS = function (meta, args) {
|
|||||||
throw new Error("METADATA_NONSENSE_PENDING_OWNERS");
|
throw new Error("METADATA_NONSENSE_PENDING_OWNERS");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var changed = false;
|
||||||
// remove owners one by one
|
// remove owners one by one
|
||||||
// we assume there are no duplicates
|
// we assume there are no duplicates
|
||||||
args.forEach(function (owner) {
|
args.forEach(function (owner) {
|
||||||
var index = meta.pending_owners.indexOf(owner);
|
var index = meta.pending_owners.indexOf(owner);
|
||||||
if (index < 0) { return; }
|
if (index < 0) { return; }
|
||||||
meta.pending_owners.splice(index, 1);
|
meta.pending_owners.splice(index, 1);
|
||||||
|
changed = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return changed;
|
||||||
};
|
};
|
||||||
|
|
||||||
// ["RESET_OWNERS", ["7eEqelGso3EBr5jHlei6av4r9w2B9XZiGGwA1EgZ-5I="], 1561623439989]
|
// ["RESET_OWNERS", ["7eEqelGso3EBr5jHlei6av4r9w2B9XZiGGwA1EgZ-5I="], 1561623439989]
|
||||||
@@ -112,6 +128,7 @@ commands.RESET_OWNERS = function (meta, args) {
|
|||||||
|
|
||||||
// overwrite the existing owners with the new one
|
// overwrite the existing owners with the new one
|
||||||
meta.owners = deduplicate(args);
|
meta.owners = deduplicate(args);
|
||||||
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
commands.UPDATE_EXPIRATION = function () {
|
commands.UPDATE_EXPIRATION = function () {
|
||||||
|
|||||||
9
rpc.js
9
rpc.js
@@ -340,6 +340,7 @@ var getMetadata = function (Env, channel, cb) {
|
|||||||
value: value
|
value: value
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
// XXX global saferphore may cause issues here, a queue "per channel" is probably better
|
||||||
var metadataSem = Saferphore.create(1);
|
var metadataSem = Saferphore.create(1);
|
||||||
var setMetadata = function (Env, data, unsafeKey, cb) {
|
var setMetadata = function (Env, data, unsafeKey, cb) {
|
||||||
var channel = data.channel;
|
var channel = data.channel;
|
||||||
@@ -382,13 +383,19 @@ var setMetadata = function (Env, data, unsafeKey, cb) {
|
|||||||
|
|
||||||
// Add the new metadata line
|
// Add the new metadata line
|
||||||
var line = [command, data.value, +new Date()];
|
var line = [command, data.value, +new Date()];
|
||||||
|
var changed = false;
|
||||||
try {
|
try {
|
||||||
Meta.handleCommand(metadata, line);
|
changed = Meta.handleCommand(metadata, line);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
g();
|
g();
|
||||||
return void cb(e);
|
return void cb(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if your command is valid but it didn't result in any change to the metadata,
|
||||||
|
// call back now and don't write any "useless" line to the log
|
||||||
|
if (!changed) {
|
||||||
|
return void cb(void 0, metadata);
|
||||||
|
}
|
||||||
Env.msgStore.writeMetadata(channel, JSON.stringify(line), function (e) {
|
Env.msgStore.writeMetadata(channel, JSON.stringify(line), function (e) {
|
||||||
g();
|
g();
|
||||||
if (e) {
|
if (e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user