Skip to content
Snippets Groups Projects
Unverified Commit ebbb8471 authored by Tasso Evangelista's avatar Tasso Evangelista Committed by GitHub
Browse files

Fix the upserting of data into cached collections (#27965)

parent 5cc83feb
No related branches found
No related tags found
No related merge requests found
...@@ -168,8 +168,8 @@ export class CachedCollection<T extends object> extends Emitter<{ changed: T; re ...@@ -168,8 +168,8 @@ export class CachedCollection<T extends object> extends Emitter<{ changed: T; re
return; return;
} }
const { _id, ...data } = newRecord; const { _id } = newRecord;
this.collection.direct.upsert({ _id } as Mongo.Selector<T>, { $set: data } as Mongo.Modifier<T>); this.collection.direct.upsert({ _id } as Mongo.Selector<T>, newRecord);
this.emit('changed', newRecord as any); // TODO: investigate why this is needed this.emit('changed', newRecord as any); // TODO: investigate why this is needed
if (hasUpdatedAt(newRecord) && newRecord._updatedAt > this.updatedAt) { if (hasUpdatedAt(newRecord) && newRecord._updatedAt > this.updatedAt) {
...@@ -232,8 +232,8 @@ export class CachedCollection<T extends object> extends Emitter<{ changed: T; re ...@@ -232,8 +232,8 @@ export class CachedCollection<T extends object> extends Emitter<{ changed: T; re
if (action === 'removed') { if (action === 'removed') {
this.collection.remove(newRecord._id); this.collection.remove(newRecord._id);
} else { } else {
const { _id, ...data } = newRecord; const { _id } = newRecord;
this.collection.direct.upsert({ _id } as Mongo.Selector<T>, { $set: data } as Mongo.Modifier<T>); this.collection.direct.upsert({ _id } as Mongo.Selector<T>, newRecord);
} }
this.save(); this.save();
}); });
...@@ -276,8 +276,8 @@ export class CachedCollection<T extends object> extends Emitter<{ changed: T; re ...@@ -276,8 +276,8 @@ export class CachedCollection<T extends object> extends Emitter<{ changed: T; re
const actionTime = newRecord._updatedAt; const actionTime = newRecord._updatedAt;
changes.push({ changes.push({
action: () => { action: () => {
const { _id, ...data } = newRecord; const { _id } = newRecord;
this.collection.direct.upsert({ _id } as Mongo.Selector<T>, { $set: data } as Mongo.Modifier<T>); this.collection.direct.upsert({ _id } as Mongo.Selector<T>, newRecord);
if (actionTime > this.updatedAt) { if (actionTime > this.updatedAt) {
this.updatedAt = actionTime; this.updatedAt = actionTime;
} }
......
...@@ -59,7 +59,7 @@ export async function upsertMessage( ...@@ -59,7 +59,7 @@ export async function upsertMessage(
); );
} }
return direct.upsert({ _id }, { $set: messageToUpsert }); return direct.upsert({ _id }, msg);
} }
export function upsertMessageBulk( export function upsertMessageBulk(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment