Remove field $loki on client side

pull/4275/head
Rodrigo Nascimento 9 years ago
parent 7dc73bff40
commit 31e9528214
No known key found for this signature in database
GPG Key ID: 2C85B3AFE75D23F9
  1. 8
      packages/rocketchat-authorization/server/publications/permissions.js
  2. 3
      packages/rocketchat-lib/client/lib/cachedCollection.js
  3. 6
      packages/rocketchat-lib/server/publications/settings.coffee
  4. 30
      packages/rocketchat-lib/server/startup/cache/_Base.js
  5. 8
      server/publications/room.js
  6. 6
      server/publications/subscription.coffee

@ -5,9 +5,11 @@ Meteor.methods({
const records = RocketChat.cache.Permissions.find().fetch();
if (updatedAt instanceof Date) {
return records.filter((record) => {
return record._updatedAt > updatedAt;
});
return {
update: records.filter((record) => {
return record._updatedAt > updatedAt;
})
};
}
return records;

@ -134,6 +134,7 @@ class CachedCollection {
Meteor.call(this.methodName, (error, data) => {
this.log(`${data.length} records loaded from server`);
data.forEach((record) => {
delete record.$loki;
this.collection.upsert({ _id: record._id }, _.omit(record, '_id'));
if (record._updatedAt && record._updatedAt > this.updatedAt) {
@ -169,6 +170,7 @@ class CachedCollection {
this.log(`${data.update.length} records updated in sync`);
for (const record of data.update) {
delete record.$loki;
this.collection.upsert({ _id: record._id }, _.omit(record, '_id'));
if (record._updatedAt && record._updatedAt > this.updatedAt) {
@ -220,6 +222,7 @@ class CachedCollection {
if (t === 'removed') {
this.collection.remove(record._id);
} else {
delete record.$loki;
this.collection.upsert({ _id: record._id }, _.omit(record, '_id'));
}

@ -28,8 +28,10 @@ Meteor.methods
return record.hidden isnt true
if updatedAt instanceof Date
return records.filter (record) ->
return record._updatedAt > updatedAt
return {
update: records.filter (record) ->
return record._updatedAt > updatedAt
}
return records

@ -496,9 +496,7 @@ RocketChat.cache._Base = (class CacheBase extends EventEmitter {
}
if (!options.fields) {
options.fields = {
$loki: 0
};
options.fields = {};
}
const fieldsToRemove = [];
@ -523,23 +521,25 @@ RocketChat.cache._Base = (class CacheBase extends EventEmitter {
fieldsToGet.push('_id');
}
if (Array.isArray(result)) {
result = result.map((record) => {
if (fieldsToRemove.length > 0 || fieldsToGet.length > 0) {
if (Array.isArray(result)) {
result = result.map((record) => {
if (fieldsToRemove.length > 0) {
return _.omit(record, ...fieldsToRemove);
}
if (fieldsToGet.length > 0) {
return _.pick(record, ...fieldsToGet);
}
});
} else {
if (fieldsToRemove.length > 0) {
return _.omit(record, ...fieldsToRemove);
return _.omit(result, ...fieldsToRemove);
}
if (fieldsToGet.length > 0) {
return _.pick(record, ...fieldsToGet);
return _.pick(result, ...fieldsToGet);
}
});
} else {
if (fieldsToRemove.length > 0) {
return _.omit(result, ...fieldsToRemove);
}
if (fieldsToGet.length > 0) {
return _.pick(result, ...fieldsToGet);
}
}

@ -35,9 +35,11 @@ Meteor.methods({
const data = RocketChat.cache.Subscriptions.findByUserId(Meteor.userId()).fetch();
if (updatedAt instanceof Date) {
return data
.filter(record => { return record._room && record._room._updatedAt > updatedAt; })
.map(roomMap);
return {
update: data
.filter(record => { return record._room && record._room._updatedAt > updatedAt; })
.map(roomMap)
};
}
return data.map(roomMap);

@ -32,8 +32,10 @@ Meteor.methods
records = RocketChat.cache.Subscriptions.findByUserId(Meteor.userId(), options).fetch()
if updatedAt instanceof Date
return records.filter (record) ->
return record._updatedAt > updatedAt
return {
update: records.filter (record) ->
return record._updatedAt > updatedAt
}
return records

Loading…
Cancel
Save