From 53f04d096df605c875c92107473d8bdcacf872e3 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 6ea0a2324..8a542fff5 100644 --- a/historyKeeper.js +++ b/historyKeeper.js @@ -771,6 +771,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... @@ -778,6 +784,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'); } });