mirror of
https://github.com/Kong/insomnia.git
synced 2026-11-06 13:04:11 -05:00
refactor(projects): add timeout parameter to fetchTeamProjects for improved performance
This commit is contained in:
2 files changed
+10
-2
No files matched your search
@@ -7,11 +7,12 @@ interface TeamProjects {
|
||||
}[];
|
||||
}
|
||||
|
||||
export const fetchTeamProjects = ({ sessionId, organizationId }: { sessionId: string; organizationId: string }) => {
|
||||
export const fetchTeamProjects = ({ sessionId, organizationId, timeout }: { sessionId: string; organizationId: string; timeout?: number }) => {
|
||||
return fetch<TeamProjects>({
|
||||
method: 'GET',
|
||||
path: `/v1/organizations/${organizationId}/team-projects`,
|
||||
sessionId,
|
||||
timeout,
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -67,6 +67,13 @@ export async function getFirstProjectOfOrganization(organizationId: string) {
|
||||
return db.findOne<Project>(type, { parentId: organizationId });
|
||||
}
|
||||
|
||||
// syncProjects() runs this in the background under the same lock that
|
||||
// guards interactive project creation (see `projectLock` in
|
||||
// packages/insomnia/src/common/project.ts), so it must not be allowed to
|
||||
// hold that lock for as long as the default fetch timeout (30s) — that
|
||||
// blocks a user's "Create project" action for far longer than they'd wait.
|
||||
const TEAM_PROJECTS_FETCH_TIMEOUT_MS = 8000;
|
||||
|
||||
export async function getAllTeamProjects(organizationId: string) {
|
||||
const { id: sessionId } = await userSessionService.get();
|
||||
if (!sessionId) {
|
||||
@@ -74,7 +81,7 @@ export async function getAllTeamProjects(organizationId: string) {
|
||||
}
|
||||
|
||||
console.log('[project] Fetching', organizationId);
|
||||
const response = await fetchTeamProjects({ sessionId, organizationId });
|
||||
const response = await fetchTeamProjects({ sessionId, organizationId, timeout: TEAM_PROJECTS_FETCH_TIMEOUT_MS });
|
||||
return response.data;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user