cozy / cozy-client

Document store and React components for the Cozy platform
MIT License
13 stars 12 forks source link

Merge requests for relationships #70

Open ptbrowne opened 6 years ago

ptbrowne commented 6 years ago

In Banks we fetch a big list of transactions and we want them to be hydrated with their bills.

client.find(TRANSACTION_DOCTYPE).include([BILL_DOCTYPE])

At the moment when relationships are fetch, they are not merged : for each transaction, one request is sent.

https://github.com/cozy/cozy-client/blob/717b22005c6ad86fbd16c871e35f80811def3b21/packages/cozy-client/src/CozyClient.js#L222-L224

https://github.com/cozy/cozy-client/blob/717b22005c6ad86fbd16c871e35f80811def3b21/packages/cozy-client/src/CozyClient.js#L267-L274

Instead of mapping directly to requests, building a (potentially big) $or request and sending 1 request should greatly reduce the number of requests (n -> 1).

Questions :

Possible plan :

nono commented 6 years ago

If you want to fetch some documents from their IDs, you can call POST /data/:doctype/_all_docs with a keys parameter in the body. The stack doesn't add a limit on the number of fetched documents on this endpoint, but if you have a very large list, if could be better to paginate with skip and limit query-string parameters by batches of 100.