Don't write metadata updates to the log if it doesn't change the value

This commit is contained in:
yflory
2019-09-02 17:16:14 +02:00
parent e131661673
commit ed5671a548
2 changed files with 26 additions and 2 deletions

9
rpc.js
View File

@@ -340,6 +340,7 @@ var getMetadata = function (Env, channel, cb) {
value: value
}
*/
// XXX global saferphore may cause issues here, a queue "per channel" is probably better
var metadataSem = Saferphore.create(1);
var setMetadata = function (Env, data, unsafeKey, cb) {
var channel = data.channel;
@@ -382,13 +383,19 @@ var setMetadata = function (Env, data, unsafeKey, cb) {
// Add the new metadata line
var line = [command, data.value, +new Date()];
var changed = false;
try {
Meta.handleCommand(metadata, line);
changed = Meta.handleCommand(metadata, line);
} catch (e) {
g();
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) {
g();
if (e) {