From 8b4b8fbe9e17452ad31b518fbce5f95ef912d7cd Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Wed, 3 Oct 2018 14:54:41 +0300 Subject: [PATCH] Fix stored image previews not being dereferenced Broken in 64ebe0f4372b789e79033b7307d0259360d96ed1 --- src/models/chan.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/models/chan.js b/src/models/chan.js index fd08e5d5..6fe7e580 100644 --- a/src/models/chan.js +++ b/src/models/chan.js @@ -84,17 +84,25 @@ Chan.prototype.pushMessage = function(client, msg, increasesUnread) { // If maxHistory is 0, image would be dereferenced before client had a chance to retrieve it, // so for now, just don't implement dereferencing for this edge case. - if (Helper.config.prefetch && Helper.config.prefetchStorage && Helper.config.maxHistory > 0) { + if (Helper.config.maxHistory > 0) { this.dereferencePreviews(deleted); } } }; Chan.prototype.dereferencePreviews = function(messages) { + if (!Helper.config.prefetch || !Helper.config.prefetchStorage) { + return; + } + messages.forEach((message) => { - if (message.preview && message.preview.thumb) { - storage.dereference(message.preview.thumb); - message.preview.thumb = null; + if (message.previews) { + message.previews.forEach((preview) => { + if (preview.thumb) { + storage.dereference(preview.thumb); + preview.thumb = null; + } + }); } }); };