I’m calling the API (https://api.airtable.com/v0/:baseId/:tableId/:viewId) to get the records from a table, using a view. There are ~1000 records in the table and about ~200 that are displayed by the view.
I’ve noticed that the first time that I call the method that calls the API can take about 10-20 to complete. Subsequent calls are subsecond.
Is this a characteristic of API itself? Perhaps it caches the dataset after the first call.
What, if anything, can I do to prevent this behavior?
This is the service layer’s method:
export const getTrainees = async () => {
console.log('AirtableService.getTrainees()')
const TABLE_ID = 'YYY';
const VIEW_ID = 'XXX';
const fields = ['Full Name'];
const params = new URLSearchParams({ view: VIEW_ID });
fields.forEach(field => params.append('fields[]', field));
const url = `${AIRTABLE_BASE_URL}/${BASE_ID}/${TABLE_ID}?${params.toString()}`;
let allRecords = [];
let offset = undefined;
do {
const pageUrl = offset ? `${url}&offset=${encodeURIComponent(offset)}` : url;
const response = await fetch(pageUrl, {
method: 'GET',
headers: {
Accept: 'application/json',
Authorization: `Bearer ${process.env.AIRTABLE_API_KEY}`
}
});
if (!response.ok) {
throw new Error(`Airtable API error: ${response.status}`);
}
const data = await response.json();
if (Array.isArray(data.records)) {
allRecords = allRecords.concat(data.records);
}
offset = data.offset;
} while (offset);
return allRecords;
}
