refactor(projects): add timeout parameter to fetchTeamProjects for improved performance

This commit is contained in:
Bob Qiu committed 2026-09-29 15:25:40 +08:00
1 parent 7d72040670
commit 136e993f68
2 files changed
+10 -2

No files matched your search

+2 -1
View File
@@ -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;
}