Add migration to clean up old expiring messages

Expiring messages received before 0.31.0 may not have an expires_at time
populated. Loading these messages once will update their expires_at if
it wasn't already set. To avoid loading too many messages into memory,
add them individually, and remove them from the collection as soon as
they are added, allowing them to be garbage collected immediately.

// FREEBIE
This commit is contained in:
lilia 2017-03-01 17:57:34 -08:00
parent 25ee61d3cb
commit 58d2f71e09
1 changed files with 19 additions and 0 deletions

View File

@ -199,6 +199,25 @@
messages.createIndex('expires_at', 'expires_at', { unique: false });
next();
}
},
{
version: "12.0",
migrate: function(transaction, next) {
console.log('migration 12.0');
console.log('cleaning up expiring messages with no expires_at');
var messages = transaction.objectStore('messages');
window.addEventListener('storage_ready', function() {
var messages = new Whisper.MessageCollection();
messages.fetch({
conditions: {expireTimer: {$gt: 0}},
addIndividually: true
});
messages.on('add', function(m) {
messages.remove(m);
});
});
next();
}
}
];
}());