Merge pull request #1406 from thelounge/xpaw/storage-dereferencing

Correctly dereference stored images when leaving channels
This commit is contained in:
Jérémie Astori 2017-08-13 12:17:02 -04:00 committed by GitHub
commit dff94cc6fd
7 changed files with 26 additions and 12 deletions

View file

@ -488,6 +488,8 @@ Client.prototype.quit = function() {
if (network.irc) {
network.irc.quit("Page closed");
}
network.destroy();
});
};

View file

@ -30,6 +30,10 @@ function Chan(attr) {
});
}
Chan.prototype.destroy = function() {
this.dereferencePreviews(this.messages);
};
Chan.prototype.pushMessage = function(client, msg, increasesUnread) {
var obj = {
chan: this.id,
@ -56,12 +60,10 @@ Chan.prototype.pushMessage = function(client, msg, increasesUnread) {
if (Helper.config.maxHistory >= 0 && this.messages.length > Helper.config.maxHistory) {
const deleted = this.messages.splice(0, this.messages.length - Helper.config.maxHistory);
if (Helper.config.prefetch && Helper.config.prefetchStorage) {
deleted.forEach((deletedMessage) => {
if (deletedMessage.preview && deletedMessage.preview.thumb) {
storage.dereference(deletedMessage.preview.thumb);
}
});
// 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) {
this.dereferencePreviews(deleted);
}
}
@ -76,6 +78,15 @@ Chan.prototype.pushMessage = function(client, msg, increasesUnread) {
}
};
Chan.prototype.dereferencePreviews = function(messages) {
messages.forEach((message) => {
if (message.preview && message.preview.thumb) {
storage.dereference(message.preview.thumb);
message.preview.thumb = null;
}
});
};
Chan.prototype.sortUsers = function(irc) {
var userModeSortPriority = {};
irc.network.options.PREFIX.forEach((prefix, index) => {

View file

@ -42,6 +42,10 @@ function Network(attr) {
);
}
Network.prototype.destroy = function() {
this.channels.forEach((channel) => channel.destroy());
};
Network.prototype.setNick = function(nick) {
this.nick = nick;
this.highlightRegex = new RegExp(

View file

@ -17,6 +17,7 @@ exports.input = function(network, chan, cmd, args) {
}
network.channels = _.without(network.channels, chan);
chan.destroy();
this.emit("part", {
chan: chan.id
});

View file

@ -11,6 +11,7 @@ exports.input = function(network, chan, cmd, args) {
var quitMessage = args[0] ? args.join(" ") : "";
client.networks = _.without(client.networks, network);
network.destroy();
client.save();
client.emit("quit", {
network: network.id

View file

@ -13,6 +13,7 @@ module.exports = function(irc, network) {
var from = data.nick;
if (from === irc.user.nick) {
network.channels = _.without(network.channels, chan);
chan.destroy();
client.save();
client.emit("part", {
chan: chan.id

View file

@ -17,12 +17,6 @@ class Storage {
}
dereference(url) {
// 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.maxHistory === 0) {
return;
}
const references = (this.references.get(url) || 0) - 1;
if (references < 0) {