From 337e0bd141361d8d975a5cd1b5ac88df94725fcf Mon Sep 17 00:00:00 2001 From: ansuz Date: Thu, 22 Aug 2019 14:52:11 +0200 Subject: [PATCH] update the server's cache whenever we write metadata --- historyKeeper.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/historyKeeper.js b/historyKeeper.js index aced95103..6de09a900 100644 --- a/historyKeeper.js +++ b/historyKeeper.js @@ -721,6 +721,12 @@ module.exports.create = function (cfg) { if (msgCount === 0 && !metadata_cache[channelName] && chan && chan.indexOf(user) > -1) { metadata_cache[channelName] = metadata; + + // the index will have already been constructed and cached at this point + // but it will not have detected any metadata because it hasn't been written yet + // this means that the cache starts off as invalid, so we have to correct it + if (chan && chan.index) { chan.index.metadata = metadata; } + // new channels will always have their metadata written to a dedicated metadata log // but any lines after the first which are not amendments in a particular format will be ignored. // Thus we should be safe from race conditions here if just write metadata to the log as below... @@ -728,6 +734,7 @@ module.exports.create = function (cfg) { // otherwise maybe we need to check that the metadata log is empty as well store.writeMetadata(channelName, JSON.stringify(metadata), function (err) { if (err) { + // XXX tell the user that there was a channel error? return void Log.error('HK_WRITE_METADATA'); } });