Skip to content

Commit 71db1d0

Browse files
committed
refactor(project): Fix stage restore
Stages where not always correctly restored from cache due to a separate initialization of all current stages (initStages)
1 parent a13a274 commit 71db1d0

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

packages/project/lib/build/cache/ProjectBuildCache.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,10 @@ export default class ProjectBuildCache {
294294
*/
295295
async #importStages(stageSignatures) {
296296
const stageNames = Object.keys(stageSignatures);
297-
this.#project.initStages(stageNames);
297+
if (this.#project.getStage()?.getId() === "initial") {
298+
// Only initialize stages once
299+
this.#project.initStages(stageNames);
300+
}
298301
const importedStages = await Promise.all(stageNames.map(async (stageName) => {
299302
const stageSignature = stageSignatures[stageName];
300303
const stageCache = await this.#findStageCache(stageName, [stageSignature]);
@@ -416,10 +419,10 @@ export default class ProjectBuildCache {
416419
const stageCache = await this.#findStageCache(stageName, stageSignatures);
417420
const oldStageSig = this.#currentStageSignatures.get(stageName)?.join("-");
418421
if (stageCache) {
422+
this.#project.setStage(stageName, stageCache.stage);
423+
419424
// Check whether the stage actually changed
420425
if (stageCache.signature !== oldStageSig) {
421-
this.#project.setStage(stageName, stageCache.stage);
422-
423426
// Store new stage signature for later use in result stage signature calculation
424427
this.#currentStageSignatures.set(stageName, stageCache.signature.split("-"));
425428

packages/project/lib/specifications/ComponentProject.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,22 +150,22 @@ class ComponentProject extends Project {
150150
throw new Error(`_getTestReader must be implemented by subclass ${this.constructor.name}`);
151151
}
152152

153-
_createWriter() {
153+
_createWriter(stageId) {
154154
// writer is always of style "buildtime"
155155
const namespaceWriter = resourceFactory.createAdapter({
156-
name: `Namespace writer for project ${this.getName()}`,
156+
name: `Namespace writer for project ${this.getName()}, stage ${stageId}`,
157157
virBasePath: "/",
158158
project: this
159159
});
160160

161161
const generalWriter = resourceFactory.createAdapter({
162-
name: `General writer for project ${this.getName()}`,
162+
name: `General writer for project ${this.getName()}, stage ${stageId}`,
163163
virBasePath: "/",
164164
project: this
165165
});
166166

167167
const collection = resourceFactory.createWriterCollection({
168-
name: `Writers for project ${this.getName()}`,
168+
name: `Writers for project ${this.getName()}, stage ${stageId}`,
169169
writerMapping: {
170170
[`/resources/${this._namespace}/`]: namespaceWriter,
171171
[`/test-resources/${this._namespace}/`]: namespaceWriter,

packages/project/lib/specifications/Project.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ class Project extends Specification {
384384
_initStageMetadata() {
385385
this.#stages = [];
386386
// Initialize with an empty stage for use without stages (i.e. without build cache)
387-
this.#currentStage = new Stage(INITIAL_STAGE_ID, this._createWriter());
387+
this.#currentStage = new Stage(INITIAL_STAGE_ID, this._createWriter(INITIAL_STAGE_ID));
388388
this.#currentStageId = INITIAL_STAGE_ID;
389389
this.#currentStageReadIndex = -1;
390390
this.#currentStageReaders = new Map();
@@ -407,7 +407,7 @@ class Project extends Specification {
407407
this._initStageMetadata();
408408
for (let i = 0; i < stageIds.length; i++) {
409409
const stageId = stageIds[i];
410-
const newStage = new Stage(stageId, this._createWriter());
410+
const newStage = new Stage(stageId, this._createWriter(stageId));
411411
this.#stages.push(newStage);
412412
}
413413
}

0 commit comments

Comments
 (0)