Reduce load from delivery receipt processing

Add a special type of collection just for retrieving group ids, which
doesn't incur the overhead of initializing a conversation model along
with all its group members.
This commit is contained in:
lilia 2016-11-17 20:10:45 +01:00
parent 0854b19371
commit a8468dae28

View file

@ -4,6 +4,23 @@
;(function() {
'use strict';
window.Whisper = window.Whisper || {};
var GroupCollection = Backbone.Collection.extend({
database: Whisper.Database,
storeName: 'conversations',
model: Backbone.Model,
fetchGroups: function(number) {
return new Promise(function(resolve) {
this.fetch({
index: {
name: 'group',
only: number
}
}).always(resolve);
}.bind(this));
}
});
Whisper.DeliveryReceipts = new (Backbone.Collection.extend({
initialize: function() {
this.on('add', this.onReceipt);
@ -24,7 +41,7 @@
},
onReceipt: function(receipt) {
var messages = new Whisper.MessageCollection();
var groups = new Whisper.ConversationCollection();
var groups = new GroupCollection();
Promise.all([
groups.fetchGroups(receipt.get('source')),
messages.fetchSentAt(receipt.get('timestamp'))