briefly cache server metadata in-memory to avoid repeated reads

pull/1/head
ansuz 4 years ago
parent e8cdbf6630
commit d4f94f3091

@ -17,7 +17,14 @@ Data.getMetadataRaw = function (Env, channel /* channelName */, _cb) {
}
Env.batchMetadata(channel, cb, function (done) {
Env.computeMetadata(channel, done);
Env.computeMetadata(channel, function (err, meta) {
if (!err && meta && meta.channel) {
Env.metadata_cache[channel] = meta;
// clear metadata after a delay if nobody has joined the channel within 30s
Env.checkCache(channel);
}
done(err, meta);
});
});
};

@ -42,6 +42,8 @@ module.exports.create = function (config) {
metadata_cache: {},
channel_cache: {},
cache_checks: {},
queueStorage: WriteQueue(),
queueDeletes: WriteQueue(),
queueValidation: WriteQueue(),
@ -117,8 +119,14 @@ module.exports.create = function (config) {
}
}());
Env.checkCache = function (channel) {
var f = Env.cache_checks[channel] || Util.throttle(function () {
if (Env.channel_cache[channel]) { return; }
delete Env.metadata_cache[channel];
delete Env.cache_checks[channel];
}, 30000);
f();
};
(function () {
var custom = config.customLimits;

Loading…
Cancel
Save