From c7ed369acb44ea17d859a536b8a9f0535fa9684e Mon Sep 17 00:00:00 2001 From: Ldoppea Date: Wed, 11 Sep 2024 16:34:51 +0200 Subject: [PATCH] fix: Await for `persistVirtualDocuments` result before finishing request 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 --- packages/cozy-client/src/CozyClient.js | 2 +- packages/cozy-client/src/associations.spec.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/cozy-client/src/CozyClient.js b/packages/cozy-client/src/CozyClient.js index 4e0ba47f92..243cd28fc7 100644 --- a/packages/cozy-client/src/CozyClient.js +++ b/packages/cozy-client/src/CozyClient.js @@ -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 diff --git a/packages/cozy-client/src/associations.spec.js b/packages/cozy-client/src/associations.spec.js index 8d53bf42e5..d4dac6c2a2 100644 --- a/packages/cozy-client/src/associations.spec.js +++ b/packages/cozy-client/src/associations.spec.js @@ -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 =>