|
|
|
@ -325,6 +325,9 @@ const storeMessage = function (Env, channel, msg, isCp, optionalMessageHash) {
|
|
|
|
|
}
|
|
|
|
|
}));
|
|
|
|
|
}).nThen((waitFor) => {
|
|
|
|
|
/* TODO we can skip updating the index if there's nobody in the channel.
|
|
|
|
|
Populating it might actually be the cause of a memory leak.
|
|
|
|
|
*/
|
|
|
|
|
getIndex(Env, id, waitFor((err, index) => {
|
|
|
|
|
if (err) {
|
|
|
|
|
Log.warn("HK_STORE_MESSAGE_INDEX", err.stack);
|
|
|
|
@ -340,7 +343,12 @@ const storeMessage = function (Env, channel, msg, isCp, optionalMessageHash) {
|
|
|
|
|
line: ((index.line || 0) + 1)
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (optionalMessageHash) {
|
|
|
|
|
/* This 'getIndex' call will construct a new index if one does not already exist.
|
|
|
|
|
If that is the case then our message will already be present and updating our offset map
|
|
|
|
|
can actually cause it to become incorrect, leading to incorrect behaviour when clients connect
|
|
|
|
|
with a lastKnownHash. We avoid this by only assigning new offsets to the map.
|
|
|
|
|
*/
|
|
|
|
|
if (optionalMessageHash && typeof(index.offsetByHash[optionalMessageHash]) === 'undefined') {
|
|
|
|
|
index.offsetByHash[optionalMessageHash] = index.size;
|
|
|
|
|
index.offsets++;
|
|
|
|
|
}
|
|
|
|
|