DB/Index Redux
This change removes the timestamp field from messages and conversations in favor of multiple semantically named timestamp fields: sent_at, received_at on messages; active_at on conversations. This requires/lets us rethink and improve our indexing scheme thusly: The inbox index on conversations will order entries by the conversation.active_at property, which should only appear on conversations destined for the inbox. The receipt index will use the message.sent_at property, for effecient lookup of outgoing messages by timestamp, for use in processing delivery receipts. The group index on conversation.members is multi-entry, meaning that looking up any phone number in this index will efficiently yield all groups the number belongs to. The conversation index lets us scan messages in a single conversation, in the order they were received (or the reverse order). It is a compound index on [conversationId, received_at].
This commit is contained in:
parent
9c736df7d0
commit
006653ed8e
5 changed files with 58 additions and 35 deletions
|
@ -19,16 +19,16 @@
|
|||
window.Whisper = window.Whisper || {};
|
||||
|
||||
var Message = Backbone.Model.extend({
|
||||
database: Whisper.Database,
|
||||
storeName: 'messages',
|
||||
defaults: function() {
|
||||
database : Whisper.Database,
|
||||
storeName : 'messages',
|
||||
defaults : function() {
|
||||
return {
|
||||
timestamp: new Date().getTime(),
|
||||
attachments: []
|
||||
};
|
||||
},
|
||||
validate: function(attributes, options) {
|
||||
var required = ['timestamp', 'conversationId'];
|
||||
var required = ['conversationId', 'received_at', 'sent_at'];
|
||||
var missing = _.filter(required, function(attr) { return !attributes[attr]; });
|
||||
if (missing.length) {
|
||||
console.log("Message missing attributes: " + missing);
|
||||
|
@ -37,11 +37,11 @@
|
|||
});
|
||||
|
||||
Whisper.MessageCollection = Backbone.Collection.extend({
|
||||
model: Message,
|
||||
database: Whisper.Database,
|
||||
storeName: 'messages',
|
||||
comparator: 'timestamp',
|
||||
destroyAll: function () {
|
||||
model : Message,
|
||||
database : Whisper.Database,
|
||||
storeName : 'messages',
|
||||
comparator : 'received_at',
|
||||
destroyAll : function () {
|
||||
return Promise.all(this.models.map(function(m) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
m.destroy().then(resolve).fail(reject);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue