This post is focused on the Looker API 4.0. As of Looker 22.4, version 3.1 is deprecated. You can read the official documentation here.
Here are some best practices to improve the API performance calls when developing with the Looker API 4.0. It will take into consideration the usage of the official SDKs, specifically the Typescript version for examples (But can be applied to any other official SDK).
const sdk = LookerNodeSDK.init40();
const search_params: IRequestSearchDashboards = {
user_id: "USER_ID",
limit: 5,
offset: 0,
};
const searched_dashboards = await sdk.ok(
sdk.search_dashboards(search_params)
);
You would need to use the user_id to filter the specific User and use limit + offset to work with pagination.
Specify the fields to be returned to reduce parsing/querying of extra attributes.
Most of the endpoints that return an object or a list of them will have the fields attribute. It is strongly recommended to use it as there are some fields that call additional internal DB queries. Therefore, by not specifying those fields, the request time will improve.
Example: This first call gets the ID, Name, Parent ID, all dashboards, all looks, and permissions ('can') from a specific folder (ID 18).
It will run slowly on larger instances because we are querying permissions for the folder ('can'), and for all of the dashboards and looks, we will get all of their attributes as well. This means that we would query each of their permissions and metadata as well. Resulting in a high number of internal DB queries.
const my_folder = await sdk.ok(
sdk.folder("18", "id,name,parent_id,dashboards,looks,can")
);
The solution to make this request run much faster, would be to specify even further the fields to be returned.
In this second call, we removed the 'can' field to skip the permission query for the folder (If for your case there's the need to use that field, use it with caution as it increases request time). And we will specify fields for the Dashboards and Looks being returned as well.
const my_folder = await sdk.ok(
sdk.folder("18", "id,name,parent_id,dashboards(id,title),looks(id,title)")
);
This will result in a much smaller list of values returned. And all the calls for permissions would be avoided as well. Making the request run much faster. At the end we want to specify the fields that will be used in our Custom Application and ignore the others.
Make usage of the API Explorer to quickly troubleshoot loading times for multiple endpoints.
Looker's API Explorer is a great tool to install in your instance to troubleshoot different endpoints in a short amount of time. You won't need to setup any SDK authentication as it uses your current user's session to make the internal calls.