Skip to content

Commit

Permalink
Small refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Savokr committed Sep 8, 2023
1 parent 8ab7842 commit e65aab0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 26 deletions.
41 changes: 19 additions & 22 deletions react-components/src/components/NodeCacheProvider/FdmNodeCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,11 @@ export class FdmNodeCache {
return this._completeRevisions.has(key);
});

const cachedEdges = await this.getCachedEdges(cachedRevisionIds, fetchViews);
if (fetchViews) {
await this.fetchAllViewsForCachedRevisions(cachedRevisionIds);
}

const cachedEdges = cachedRevisionIds.map((id) => this.getCachedEdgesForRevision(id));

const revisionToEdgesMap = await this.getAndCacheRevisionToEdgesMap(
nonCachedRevisionIds,
Expand All @@ -182,32 +186,25 @@ export class FdmNodeCache {
return revisionToEdgesMap;
}

private async getCachedEdges(
modelRevisionIds: ModelRevisionId[],
fetchViews: boolean = false
): Promise<Array<[ModelRevisionKey, FdmEdgeWithNode[]]>> {
const cachedEdges = modelRevisionIds.map(
async (id) => await this.getCachedEdgesForRevision(id, fetchViews)
);

const edges = await Promise.all(cachedEdges);

return edges;
}

private async getCachedEdgesForRevision(
id: {
private async fetchAllViewsForCachedRevisions(
revisions: Array<{
modelId: number;
revisionId: number;
},
fetchViews = false
): Promise<[ModelRevisionKey, FdmEdgeWithNode[]]> {
const revisionCache = this.getOrCreateRevisionCache(id.modelId, id.revisionId);
const revisionKey = createModelRevisionKey(id.modelId, id.revisionId);
}>
): Promise<void> {
for (const revision of revisions) {
const revisionCache = this.getOrCreateRevisionCache(revision.modelId, revision.revisionId);

if (fetchViews) {
await revisionCache.fetchViewsForAllEdges();
}
}

private getCachedEdgesForRevision(id: {
modelId: number;
revisionId: number;
}): [ModelRevisionKey, FdmEdgeWithNode[]] {
const revisionCache = this.getOrCreateRevisionCache(id.modelId, id.revisionId);
const revisionKey = createModelRevisionKey(id.modelId, id.revisionId);

const cachedRevisionEdges = revisionCache.getAllEdges();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,18 +183,18 @@ export class RevisionFdmNodeCache {
}

public async fetchViewsForAllEdges(): Promise<void> {
const allEdges = this.getAllEdges();
const allEdgesWithoutView = this.getAllEdges().filter((edge) => edge.view === undefined);

if (allEdges.length === 0) {
if (allEdgesWithoutView.length === 0) {
return;
}

const nodeInspectionResults = await inspectNodes(
this._fdmClient,
allEdges.map((edge) => edge.edge.startNode)
allEdgesWithoutView.map((edge) => edge.edge.startNode)
);

allEdges.forEach((fdmEdgeWithNode, ind) => {
allEdgesWithoutView.forEach((fdmEdgeWithNode, ind) => {
const edgeWithView = {
...fdmEdgeWithNode,
view: nodeInspectionResults.items[ind].inspectionResults.involvedViewsAndContainers.views[0]
Expand Down

0 comments on commit e65aab0

Please sign in to comment.