Skip to content
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion packages/cozy-client/src/CozyClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -1157,7 +1157,18 @@ client.query(Q('io.cozy.bills'))`)
if (!Array.isArray(data)) {
await this.persistVirtualDocument(data, enforce)
} else {
for (const document of data) {
const documentsToPersist = data.filter(document => {
if (!document || document.cozyLocalOnly) {
return false
}

if ((!document.meta?.rev && !document._rev) || enforce) {
return true
}

return false
})
for (const document of documentsToPersist) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really better? OK you don't call a method if not needed, but now you loop twice

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually significantly better. After a big query retrieving 25K docs, the persistVirtualDocuments takes:

  • Before: 609ms
  • After: 20ms

I wonder if this is because of the event loop overwhelmed by too many calls

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh shit, I didn't saw that the persistVirtualDocument was async... This is why.

nit: You can now remove the check within the persistVirtualDocument method since should only call it with the docs to persist ^^.

await this.persistVirtualDocument(document, enforce)
}
}
Expand Down