Use cache to send subscription date to client

pull/4275/head
Rodrigo Nascimento 10 years ago
parent cd511e7ba2
commit 30a99b2297
No known key found for this signature in database
GPG Key ID: 2C85B3AFE75D23F9
  1. 5
      packages/rocketchat-lib/server/startup/cache/Subscriptions.js
  2. 14
      server/publications/subscription.coffee

@ -5,12 +5,17 @@ RocketChat.cache.Subscriptions = new (class CacheUser extends RocketChat.cache._
super('Subscriptions');
this.ensureIndex('rid', 'array');
this.ensureIndex('u._id', 'array');
this.ensureIndex(['rid', 'u._id'], 'unique');
}
findByUserId(userId, options) {
return this.findByIndex('u._id', userId, options);
}
findOneByRidAndUserId(rid, userId, options) {
return this.findByIndex('rid,u._id', [rid, userId], options).fetch();
}
});
RocketChat.cache.Rooms.hasMany('Subscriptions', {

@ -29,14 +29,14 @@ Meteor.methods
options =
fields: fields
if updatedAt instanceof Date
return RocketChat.models.Subscriptions.dinamicFindChangesAfter('findByUserId', updatedAt, Meteor.userId(), options)
records = RocketChat.cache.Subscriptions.findByUserId(Meteor.userId(), options).fetch()
return RocketChat.models.Subscriptions.findByUserId(Meteor.userId(), options).fetch()
if updatedAt instanceof Date
return records.filter (record) ->
return record._updatedAt > updatedAt
return records
RocketChat.models.Subscriptions.on 'change', (type, args...) ->
records = RocketChat.models.Subscriptions.getChangedRecords type, args[0], fields
for record in records
RocketChat.Notifications.notifyUser record.u._id, 'subscriptions-changed', type, record
RocketChat.cache.Subscriptions.on 'changed', (type, subscription) ->
RocketChat.Notifications.notifyUser subscription.u._id, 'subscriptions-changed', type, RocketChat.cache.Subscriptions.processQueryOptionsOnResult(subscription, {fields: fields})

Loading…
Cancel
Save