Implement custom request aggregation for certain API endpoints
When the dashboard encounters an object id reference that needs to be resolved it dispatches a request for that referenced object through the store. This happens in the form of store.retrieve(objectId)
calls and often only dispatches requests if the object hasn’t been loaded before. This behavior is easy to understand and reason about. However, in some situations the dashboard dispatches a lot (10+) of requests for multiple objects from the same resource collection in a very short time frame. This often happens when switching views – e.g. in the calendar.
Some of the endpoints representing the resource collection support the ids=...
query parameter (or something similar) that restricts the response dataset to objects with the specified ids. In order to optimize the request load, we could transform the individual store.retrieve
operations to a single request, by introducing a small aggregation window (like 30ms), in which we aggregate requests on the same resource.
Basically, instead of
const obj1 = store.retrieve(1)
const obj2 = store.retrieve(2)
const obj3 = store.retrieve(3)
we would do:
const data = store.list({ query: new URLSearchParameters({ ids: [1, 2, 3].join(',') })
const obj1 = data.then(list => list.find(obj => obj.id === 1))
const obj2 = data.then(list => list.find(obj => obj.id === 2))
const obj3 = data.then(list => list.find(obj => obj.id === 3))
Not all of the endpoints support the ids
query parameter so this optimization strategy must configurable. The aggregation window time should be configurable as well.