Hello,
I have one very specific question.
Here is the case:
Requests made with builder.getAll(…) from '@builder.io/react'
are significantly slower than requests made with plain old fetch.
Example:
The data fetched is a section model (134 entities) in my dev environment (meaning - localhost).
-
With builder.getAll(…) takes no less then 5s (sometimes it goes up to 15s), the data is give or take 500 kb in size, and i am using limit + offset, but this does not quite matter, as i am referring to the first request:
And this is the function with builder.getAll(…)
export const getBuilderIoDataAboveTheLimit = async (
modelId: BuilderIoModelIDs,
opts?: BuilderIoOptions
) => {
const _limit = 100;
let _offset = 0;
const getData = async () => {
return await builder.getAll(modelId, {
options: { enrich: true, offset: _offset, noTargeting: true },
limit: _limit,
includeUnpublished: true,
query: opts?.query,
sort: opts?.sort,
});
};
const results = await getData();
while (results.length === _limit + _offset) {
_offset += _limit;
const nextResults = await getData();
results.push(...nextResults);
}
return results;
-
Now with the fetch is way better.
This is the function with fetch
export const getBuilderIoDataAboveTheLimit = async (
modelId: BuilderIoModelIDs,
opts?: BuilderIoOptions
) => {
const _limit = 100;
let _offset = 0;
const query = opts?.query ? `&${opts.query}` : '';
const sort = opts?.sort ? `&${opts.sort}` : '';
const getData = async () => {
return await fetch(
`https://cdn.builder.io/api/v3/content/${modelId}?apiKey=${APY_KEY}&limit=${_limit}&offset=${_offset}$cachebust=true&includeUnpublished=true${query}${sort}`
);
};
const data = await getData();
while (data.length === _limit + _offset) {
_offset += _limit;
const nextData = await getData();
data.push(...nextData);
}
return data;
};
So why is there such a big difference in speed/time and what should i do. Use the plain old fetch or do something about builder.getAll(…) and use it instead … ?