Skip to content

Commit

Permalink
fix: Await for persistVirtualDocuments result before finishing request
Browse files Browse the repository at this point in the history
In previous implementation we did not await for the
`persistVirtualDocuments()` result before completing the request

This was done because the persistance was not mandatory for the
request's result and doing it in parallel would be a good way to
optimize timings

But in some recent experiments we found a scenario where we would
benefit from the `await` in order to some external code until the data
is actually persisted

Related PR: #1486
  • Loading branch information
Ldoppea committed Sep 11, 2024
1 parent 9c0c0c6 commit 9aae2d9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/cozy-client/src/CozyClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -1093,7 +1093,7 @@ client.query(Q('io.cozy.bills'))`)
async requestQuery(definition) {
const mainResponse = await this.chain.request(definition)

this.persistVirtualDocuments(definition, mainResponse.data)
await this.persistVirtualDocuments(definition, mainResponse.data)

if (!definition.includes) {
return mainResponse
Expand Down
3 changes: 2 additions & 1 deletion packages/cozy-client/src/associations.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import { SCHEMA, TODO_1, TODO_2 } from './__tests__/fixtures'

describe('Associations', () => {
const requestHandler = jest.fn()
const link = new CozyLink(requestHandler)
const persistHandler = jest.fn()
const link = new CozyLink(requestHandler, persistHandler)
const client = new CozyClient({ links: [link], schema: SCHEMA })

const getTodo = id =>
Expand Down

0 comments on commit 9aae2d9

Please sign in to comment.