Skip to content

Commit

Permalink
Tweaks to release
Browse files Browse the repository at this point in the history
  • Loading branch information
lancegliser committed Apr 25, 2024
1 parent e15823b commit 8377087
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/client/wasm/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ import { CacheMap, isNode, batcher, BatchOptions } from "../utilities/index";
import { FileSystemClient } from "./files";
import { AmalgamError } from "@howso/amalgam-lang";

export interface TraineeCache extends TraineeBaseCache {
entityId: string;
}
export interface TraineeCache extends TraineeBaseCache {}

export interface ClientOptions {
trace?: boolean;
Expand Down Expand Up @@ -376,7 +374,7 @@ export class WasmClient extends BaseClient implements ITraineeClient, ISessionCl
// Get trainee details. Use the internal method to prevent auto resolution loops.
const trainee = await this._getTraineeFromCore(traineeId);
// Cache the trainee
this.traineeCache.set(traineeId, { trainee, entityId: traineeId });
this.traineeCache.set(traineeId, { trainee });
}

/**
Expand All @@ -389,8 +387,9 @@ export class WasmClient extends BaseClient implements ITraineeClient, ISessionCl
}

// Check if trainee already loaded
const cached = this.traineeCache.get(traineeId);
if (cached?.entityId == traineeId) {
const trainee = await this.autoResolveTrainee(traineeId);
const cached = this.traineeCache.get(trainee.id);
if (cached) {
if (["allow", "always"].indexOf(String(cached.trainee.persistence)) != -1) {
// Auto save the trainee
await this.execute(traineeId, "save", {
Expand All @@ -402,9 +401,14 @@ export class WasmClient extends BaseClient implements ITraineeClient, ISessionCl
"Trainees set to never persist may not have their resources released. Delete the trainee instead.",
);
}
this.traineeCache.discard(traineeId);
}
this.traineeCache.discard(traineeId);
await this.execute(traineeId, "delete", { trainee: traineeId });

await this.dispatch({
type: "request",
command: "destroyEntity",
parameters: [traineeId],
});
}

/**
Expand Down Expand Up @@ -449,13 +453,11 @@ export class WasmClient extends BaseClient implements ITraineeClient, ISessionCl

// Set the feature attributes
await this.execute(traineeId, "set_feature_attributes", { features });
const { content: allFeatures = features } = await this.execute(traineeId, "get_feature_attributes", {
trainee: traineeId,
});
const allFeatures = await this._getFeatureAttributes(traineeId);

// Build, cache and return new trainee object
const newTrainee: Trainee = TraineeFromJSON({ ...metadata, id: traineeId, features: allFeatures }) as Trainee;
this.traineeCache.set(traineeId, { trainee: newTrainee, entityId: traineeId });
this.traineeCache.set(traineeId, { trainee: newTrainee });
return newTrainee;
}

Expand Down

0 comments on commit 8377087

Please sign in to comment.