From a8468dae286f224e80603986489b0536684e9a68 Mon Sep 17 00:00:00 2001 From: lilia Date: Thu, 17 Nov 2016 20:10:45 +0100 Subject: [PATCH] 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. --- js/delivery_receipts.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/js/delivery_receipts.js b/js/delivery_receipts.js index 5d642119..db4e7321 100644 --- a/js/delivery_receipts.js +++ b/js/delivery_receipts.js @@ -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'))