Skip to content

Commit d116db9

Browse files
committed
Do expensive image and prebuild promises in parallel
1 parent 29e6aa6 commit d116db9

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

components/server/src/prebuilds/incremental-workspace-service.ts

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { PrebuildWithWorkspace, WorkspaceDB } from "@gitpod/gitpod-db/lib";
2020
import { Config } from "../config";
2121
import { HostContextProvider } from "../auth/host-context-provider";
2222
import { ImageSourceProvider } from "../workspace/image-source-provider";
23+
import { ApplicationError, ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error";
2324

2425
const MAX_HISTORY_DEPTH = 100;
2526

@@ -81,21 +82,35 @@ export class IncrementalWorkspaceService {
8182
return;
8283
}
8384

84-
const imageSourcePromise = this.imageSourceProvider.getImageSource({}, user, context, config);
85-
86-
// Note: This query returns only not-garbage-collected prebuilds in order to reduce cardinality
87-
// (e.g., at the time of writing, the Gitpod repository has 16K+ prebuilds, but only ~300 not-garbage-collected)
88-
const recentPrebuilds = await this.workspaceDB.findPrebuildsWithWorkspace(projectId);
89-
const imageSource = await imageSourcePromise;
85+
const [recentPrebuilds, imageSource] = await Promise.allSettled([
86+
// Note: This query returns only not-garbage-collected prebuilds in order to reduce cardinality
87+
// (e.g., at the time of writing, the Gitpod repository has 16K+ prebuilds, but only ~300 not-garbage-collected)
88+
this.workspaceDB.findPrebuildsWithWorkspace(projectId),
89+
this.imageSourceProvider.getImageSource({}, user, context, config),
90+
]);
91+
if (imageSource.status === "rejected") {
92+
log.error("Image source promise was rejected", { reason: imageSource.reason, userId: user.id });
93+
throw new ApplicationError(
94+
ErrorCodes.INTERNAL_SERVER_ERROR,
95+
"Something went wrong when looking up prebuilds",
96+
);
97+
}
98+
if (recentPrebuilds.status === "rejected") {
99+
log.error("Prebuild lookup promise was rejected", { reason: recentPrebuilds.reason, userId: user.id });
100+
throw new ApplicationError(
101+
ErrorCodes.INTERNAL_SERVER_ERROR,
102+
"Something went wrong when looking up prebuilds",
103+
);
104+
}
90105

91106
// traverse prebuilds by commit history instead of their creationTime, so that we don't match prebuilds created for older revisions but triggered later
92107
const candidates: { candidate: PrebuildWithWorkspace; index: number }[] = [];
93-
for (const recentPrebuild of recentPrebuilds) {
108+
for (const recentPrebuild of recentPrebuilds.value) {
94109
const { prebuild, workspace } = recentPrebuild;
95110
const { match, index } = this.isMatchForIncrementalBuild(
96111
history,
97112
config,
98-
imageSource,
113+
imageSource.value,
99114
prebuild,
100115
workspace,
101116
includeUnfinishedPrebuilds,

0 commit comments

Comments
 (0)