@itwin/tree-widget-react 3.15.0 → 3.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -2
- package/lib/cjs/tree-widget-react/TreeWidget.d.ts +1 -2
- package/lib/cjs/tree-widget-react/TreeWidget.js +12 -12
- package/lib/cjs/tree-widget-react/TreeWidget.js.map +1 -1
- package/lib/cjs/tree-widget-react/components/trees/categories-tree/CategoriesTreeButtons.d.ts +2 -3
- package/lib/cjs/tree-widget-react/components/trees/categories-tree/CategoriesTreeButtons.js +5 -4
- package/lib/cjs/tree-widget-react/components/trees/categories-tree/CategoriesTreeButtons.js.map +1 -1
- package/lib/cjs/tree-widget-react/components/trees/categories-tree/CategoriesTreeDefinition.d.ts +4 -7
- package/lib/cjs/tree-widget-react/components/trees/categories-tree/CategoriesTreeDefinition.js +39 -31
- package/lib/cjs/tree-widget-react/components/trees/categories-tree/CategoriesTreeDefinition.js.map +1 -1
- package/lib/cjs/tree-widget-react/components/trees/categories-tree/UseCategoriesTree.js +6 -2
- package/lib/cjs/tree-widget-react/components/trees/categories-tree/UseCategoriesTree.js.map +1 -1
- package/lib/cjs/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.d.ts +3 -11
- package/lib/cjs/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.js +45 -36
- package/lib/cjs/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.js.map +1 -1
- package/lib/cjs/tree-widget-react/components/trees/categories-tree/internal/CategoriesVisibilityHandler.d.ts +1 -3
- package/lib/cjs/tree-widget-react/components/trees/categories-tree/internal/CategoriesVisibilityHandler.js +30 -30
- package/lib/cjs/tree-widget-react/components/trees/categories-tree/internal/CategoriesVisibilityHandler.js.map +1 -1
- package/lib/cjs/tree-widget-react/components/trees/common/CategoriesVisibilityUtils.d.ts +2 -7
- package/lib/cjs/tree-widget-react/components/trees/common/CategoriesVisibilityUtils.js +8 -21
- package/lib/cjs/tree-widget-react/components/trees/common/CategoriesVisibilityUtils.js.map +1 -1
- package/lib/cjs/tree-widget-react/components/trees/common/internal/useTreeHooks/UseIdsCache.d.ts +3 -0
- package/lib/cjs/tree-widget-react/components/trees/common/internal/useTreeHooks/UseIdsCache.js +7 -7
- package/lib/cjs/tree-widget-react/components/trees/common/internal/useTreeHooks/UseIdsCache.js.map +1 -1
- package/lib/cjs/tree-widget-react/components/trees/common/useGuid.d.ts +2 -0
- package/lib/cjs/tree-widget-react/components/trees/common/useGuid.js +14 -0
- package/lib/cjs/tree-widget-react/components/trees/common/useGuid.js.map +1 -0
- package/lib/cjs/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTree.js +4 -1
- package/lib/cjs/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTree.js.map +1 -1
- package/lib/cjs/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTreeDefinition.d.ts +4 -6
- package/lib/cjs/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTreeDefinition.js +31 -26
- package/lib/cjs/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTreeDefinition.js.map +1 -1
- package/lib/cjs/tree-widget-react/components/trees/imodel-content-tree/IModelContentTree.d.ts +1 -1
- package/lib/cjs/tree-widget-react/components/trees/imodel-content-tree/IModelContentTree.js +4 -2
- package/lib/cjs/tree-widget-react/components/trees/imodel-content-tree/IModelContentTree.js.map +1 -1
- package/lib/cjs/tree-widget-react/components/trees/imodel-content-tree/IModelContentTreeDefinition.d.ts +1 -5
- package/lib/cjs/tree-widget-react/components/trees/imodel-content-tree/IModelContentTreeDefinition.js +44 -44
- package/lib/cjs/tree-widget-react/components/trees/imodel-content-tree/IModelContentTreeDefinition.js.map +1 -1
- package/lib/cjs/tree-widget-react/components/trees/imodel-content-tree/internal/IModelContentTreeIdsCache.d.ts +3 -6
- package/lib/cjs/tree-widget-react/components/trees/imodel-content-tree/internal/IModelContentTreeIdsCache.js +20 -16
- package/lib/cjs/tree-widget-react/components/trees/imodel-content-tree/internal/IModelContentTreeIdsCache.js.map +1 -1
- package/lib/cjs/tree-widget-react/components/trees/models-tree/ModelsTreeButtons.js +3 -1
- package/lib/cjs/tree-widget-react/components/trees/models-tree/ModelsTreeButtons.js.map +1 -1
- package/lib/cjs/tree-widget-react/components/trees/models-tree/ModelsTreeDefinition.d.ts +6 -10
- package/lib/cjs/tree-widget-react/components/trees/models-tree/ModelsTreeDefinition.js +107 -64
- package/lib/cjs/tree-widget-react/components/trees/models-tree/ModelsTreeDefinition.js.map +1 -1
- package/lib/cjs/tree-widget-react/components/trees/models-tree/UseModelsTree.js +18 -8
- package/lib/cjs/tree-widget-react/components/trees/models-tree/UseModelsTree.js.map +1 -1
- package/lib/cjs/tree-widget-react/components/trees/models-tree/Utils.d.ts +24 -0
- package/lib/cjs/tree-widget-react/components/trees/models-tree/Utils.js +46 -0
- package/lib/cjs/tree-widget-react/components/trees/models-tree/Utils.js.map +1 -1
- package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/AlwaysAndNeverDrawnElementInfo.d.ts +40 -9
- package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/AlwaysAndNeverDrawnElementInfo.js +68 -39
- package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/AlwaysAndNeverDrawnElementInfo.js.map +1 -1
- package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/FilteredTree.d.ts +13 -5
- package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/FilteredTree.js +20 -14
- package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/FilteredTree.js.map +1 -1
- package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.d.ts +5 -13
- package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.js +70 -60
- package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.js.map +1 -1
- package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.d.ts +6 -2
- package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.js +189 -197
- package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.js.map +1 -1
- package/lib/esm/tree-widget-react/TreeWidget.d.ts +1 -2
- package/lib/esm/tree-widget-react/TreeWidget.js +12 -12
- package/lib/esm/tree-widget-react/TreeWidget.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeButtons.d.ts +2 -3
- package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeButtons.js +5 -3
- package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeButtons.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeDefinition.d.ts +4 -7
- package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeDefinition.js +39 -31
- package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeDefinition.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/categories-tree/UseCategoriesTree.js +6 -2
- package/lib/esm/tree-widget-react/components/trees/categories-tree/UseCategoriesTree.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.d.ts +3 -11
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.js +45 -36
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesVisibilityHandler.d.ts +1 -3
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesVisibilityHandler.js +30 -30
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesVisibilityHandler.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/common/CategoriesVisibilityUtils.d.ts +2 -7
- package/lib/esm/tree-widget-react/components/trees/common/CategoriesVisibilityUtils.js +8 -20
- package/lib/esm/tree-widget-react/components/trees/common/CategoriesVisibilityUtils.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/common/internal/useTreeHooks/UseIdsCache.d.ts +3 -0
- package/lib/esm/tree-widget-react/components/trees/common/internal/useTreeHooks/UseIdsCache.js +7 -7
- package/lib/esm/tree-widget-react/components/trees/common/internal/useTreeHooks/UseIdsCache.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/common/useGuid.d.ts +2 -0
- package/lib/esm/tree-widget-react/components/trees/common/useGuid.js +11 -0
- package/lib/esm/tree-widget-react/components/trees/common/useGuid.js.map +1 -0
- package/lib/esm/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTree.js +4 -1
- package/lib/esm/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTree.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTreeDefinition.d.ts +4 -6
- package/lib/esm/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTreeDefinition.js +31 -26
- package/lib/esm/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTreeDefinition.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTree.d.ts +1 -1
- package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTree.js +4 -2
- package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTree.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTreeDefinition.d.ts +1 -5
- package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTreeDefinition.js +44 -44
- package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTreeDefinition.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/internal/IModelContentTreeIdsCache.d.ts +3 -6
- package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/internal/IModelContentTreeIdsCache.js +21 -17
- package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/internal/IModelContentTreeIdsCache.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeButtons.js +3 -1
- package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeButtons.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeDefinition.d.ts +6 -10
- package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeDefinition.js +107 -64
- package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeDefinition.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/models-tree/UseModelsTree.js +18 -8
- package/lib/esm/tree-widget-react/components/trees/models-tree/UseModelsTree.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/models-tree/Utils.d.ts +24 -0
- package/lib/esm/tree-widget-react/components/trees/models-tree/Utils.js +44 -0
- package/lib/esm/tree-widget-react/components/trees/models-tree/Utils.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/AlwaysAndNeverDrawnElementInfo.d.ts +40 -9
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/AlwaysAndNeverDrawnElementInfo.js +70 -41
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/AlwaysAndNeverDrawnElementInfo.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/FilteredTree.d.ts +13 -5
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/FilteredTree.js +22 -16
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/FilteredTree.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.d.ts +5 -13
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.js +71 -61
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.d.ts +6 -2
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.js +192 -200
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.js.map +1 -1
- package/package.json +8 -8
package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.d.ts
CHANGED
|
@@ -1,20 +1,11 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { Id64Arg, Id64Array, Id64String } from "@itwin/core-bentley";
|
|
1
|
+
import type { GuidString, Id64Arg, Id64Array, Id64Set, Id64String } from "@itwin/core-bentley";
|
|
3
2
|
import type { HierarchyNodeIdentifiersPath, LimitingECSqlQueryExecutor } from "@itwin/presentation-hierarchies";
|
|
3
|
+
import type { ModelsTreeDefinition } from "../ModelsTreeDefinition.js";
|
|
4
4
|
type ModelsTreeHierarchyConfiguration = ConstructorParameters<typeof ModelsTreeDefinition>[0]["hierarchyConfig"];
|
|
5
5
|
/** @internal */
|
|
6
6
|
export declare class ModelsTreeIdsCache implements Disposable {
|
|
7
|
-
private
|
|
8
|
-
|
|
9
|
-
private readonly _categoryElementCounts;
|
|
10
|
-
private _subjectInfos;
|
|
11
|
-
private _parentSubjectIds;
|
|
12
|
-
private _modelInfos;
|
|
13
|
-
private _modelWithCategoryModeledElements;
|
|
14
|
-
private _modelKeyPaths;
|
|
15
|
-
private _subjectKeyPaths;
|
|
16
|
-
private _categoryKeyPaths;
|
|
17
|
-
constructor(_queryExecutor: LimitingECSqlQueryExecutor, _hierarchyConfig: ModelsTreeHierarchyConfiguration);
|
|
7
|
+
#private;
|
|
8
|
+
constructor(queryExecutor: LimitingECSqlQueryExecutor, hierarchyConfig: ModelsTreeHierarchyConfiguration, componentId?: GuidString);
|
|
18
9
|
[Symbol.dispose](): void;
|
|
19
10
|
private querySubjects;
|
|
20
11
|
private queryModels;
|
|
@@ -35,6 +26,7 @@ export declare class ModelsTreeIdsCache implements Disposable {
|
|
|
35
26
|
private queryModeledElements;
|
|
36
27
|
private getModelWithCategoryModeledElements;
|
|
37
28
|
private getModelInfos;
|
|
29
|
+
getAllCategories(): Promise<Id64Set>;
|
|
38
30
|
getModelCategories(modelId: Id64String): Promise<Id64Array>;
|
|
39
31
|
hasSubModel(elementId: Id64String): Promise<boolean>;
|
|
40
32
|
getCategoriesModeledElements(modelId: Id64String, categoryIds: Id64Arg): Promise<Id64Array>;
|
package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.js
CHANGED
|
@@ -3,32 +3,36 @@
|
|
|
3
3
|
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
4
|
*--------------------------------------------------------------------------------------------*/
|
|
5
5
|
import { bufferCount, bufferTime, filter, firstValueFrom, from, map, mergeAll, mergeMap, reduce, ReplaySubject, Subject } from "rxjs";
|
|
6
|
-
import { assert, Id64 } from "@itwin/core-bentley";
|
|
6
|
+
import { assert, Guid, Id64 } from "@itwin/core-bentley";
|
|
7
7
|
import { IModel } from "@itwin/core-common";
|
|
8
8
|
import { collect } from "../../common/Rxjs.js";
|
|
9
9
|
import { pushToMap } from "../../common/Utils.js";
|
|
10
10
|
/** @internal */
|
|
11
11
|
export class ModelsTreeIdsCache {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
this
|
|
26
|
-
this
|
|
27
|
-
this
|
|
28
|
-
this
|
|
12
|
+
#categoryElementCounts;
|
|
13
|
+
#subjectInfos;
|
|
14
|
+
#parentSubjectIds; // the list should contain a subject id if its node should be shown as having children
|
|
15
|
+
#modelInfos;
|
|
16
|
+
#modelWithCategoryModeledElements;
|
|
17
|
+
#modelKeyPaths;
|
|
18
|
+
#subjectKeyPaths;
|
|
19
|
+
#categoryKeyPaths;
|
|
20
|
+
#queryExecutor;
|
|
21
|
+
#hierarchyConfig;
|
|
22
|
+
#componentId;
|
|
23
|
+
#componentName;
|
|
24
|
+
constructor(queryExecutor, hierarchyConfig, componentId) {
|
|
25
|
+
this.#hierarchyConfig = hierarchyConfig;
|
|
26
|
+
this.#queryExecutor = queryExecutor;
|
|
27
|
+
this.#categoryElementCounts = new ModelCategoryElementsCountCache(async (input) => this.queryCategoryElementCounts(input));
|
|
28
|
+
this.#modelKeyPaths = new Map();
|
|
29
|
+
this.#subjectKeyPaths = new Map();
|
|
30
|
+
this.#categoryKeyPaths = new Map();
|
|
31
|
+
this.#componentId = componentId ?? Guid.createValue();
|
|
32
|
+
this.#componentName = "ModelsTreeIdsCache";
|
|
29
33
|
}
|
|
30
34
|
[Symbol.dispose]() {
|
|
31
|
-
this
|
|
35
|
+
this.#categoryElementCounts[Symbol.dispose]();
|
|
32
36
|
}
|
|
33
37
|
async *querySubjects() {
|
|
34
38
|
const subjectsQuery = `
|
|
@@ -40,7 +44,7 @@ export class ModelsTreeIdsCache {
|
|
|
40
44
|
FROM bis.GeometricModel3d m
|
|
41
45
|
WHERE m.ECInstanceId = HexToId(json_extract(s.JsonProperties, '$.Subject.Model.TargetPartition'))
|
|
42
46
|
AND NOT m.IsPrivate
|
|
43
|
-
AND EXISTS (SELECT 1 FROM ${this.
|
|
47
|
+
AND EXISTS (SELECT 1 FROM ${this.#hierarchyConfig.elementClassSpecification} WHERE Model.Id = m.ECInstanceId)
|
|
44
48
|
) targetPartitionId,
|
|
45
49
|
CASE
|
|
46
50
|
WHEN (
|
|
@@ -51,7 +55,7 @@ export class ModelsTreeIdsCache {
|
|
|
51
55
|
END hideInHierarchy
|
|
52
56
|
FROM bis.Subject s
|
|
53
57
|
`;
|
|
54
|
-
for await (const row of this.
|
|
58
|
+
for await (const row of this.#queryExecutor.createQueryReader({ ecsql: subjectsQuery }, { rowFormat: "ECSqlPropertyNames", limit: "unbounded", restartToken: `${this.#componentName}/${this.#componentId}/subjects` })) {
|
|
55
59
|
yield { id: row.id, parentId: row.parentId, targetPartitionId: row.targetPartitionId, hideInHierarchy: !!row.hideInHierarchy };
|
|
56
60
|
}
|
|
57
61
|
}
|
|
@@ -62,14 +66,14 @@ export class ModelsTreeIdsCache {
|
|
|
62
66
|
INNER JOIN bis.GeometricModel3d m ON m.ModeledElement.Id = p.ECInstanceId
|
|
63
67
|
WHERE
|
|
64
68
|
NOT m.IsPrivate
|
|
65
|
-
${this.
|
|
69
|
+
${this.#hierarchyConfig.showEmptyModels ? "" : `AND EXISTS (SELECT 1 FROM ${this.#hierarchyConfig.elementClassSpecification} WHERE Model.Id = m.ECInstanceId)`}
|
|
66
70
|
`;
|
|
67
|
-
for await (const row of this.
|
|
71
|
+
for await (const row of this.#queryExecutor.createQueryReader({ ecsql: modelsQuery }, { rowFormat: "ECSqlPropertyNames", limit: "unbounded", restartToken: `${this.#componentName}/${this.#componentId}/models` })) {
|
|
68
72
|
yield { id: row.id, parentId: row.parentId };
|
|
69
73
|
}
|
|
70
74
|
}
|
|
71
75
|
async getSubjectInfos() {
|
|
72
|
-
this
|
|
76
|
+
this.#subjectInfos ??= (async () => {
|
|
73
77
|
const [subjectInfos, targetPartitionSubjects] = await Promise.all([
|
|
74
78
|
(async () => {
|
|
75
79
|
const result = new Map();
|
|
@@ -111,11 +115,11 @@ export class ModelsTreeIdsCache {
|
|
|
111
115
|
}
|
|
112
116
|
return subjectInfos;
|
|
113
117
|
})();
|
|
114
|
-
return this
|
|
118
|
+
return this.#subjectInfos;
|
|
115
119
|
}
|
|
116
120
|
/** Returns ECInstanceIDs of Subjects that either have direct Model or at least one child Subject with a Model. */
|
|
117
121
|
async getParentSubjectIds() {
|
|
118
|
-
this
|
|
122
|
+
this.#parentSubjectIds ??= (async () => {
|
|
119
123
|
const subjectInfos = await this.getSubjectInfos();
|
|
120
124
|
const parentSubjectIds = new Set();
|
|
121
125
|
subjectInfos.forEach((subjectInfo, subjectId) => {
|
|
@@ -130,7 +134,7 @@ export class ModelsTreeIdsCache {
|
|
|
130
134
|
});
|
|
131
135
|
return [...parentSubjectIds];
|
|
132
136
|
})();
|
|
133
|
-
return this
|
|
137
|
+
return this.#parentSubjectIds;
|
|
134
138
|
}
|
|
135
139
|
/**
|
|
136
140
|
* Returns child subjects of the specified parent subjects as they're displayed in the hierarchy - taking into
|
|
@@ -190,14 +194,14 @@ export class ModelsTreeIdsCache {
|
|
|
190
194
|
return modelIds;
|
|
191
195
|
}
|
|
192
196
|
async createSubjectInstanceKeysPath(targetSubjectId) {
|
|
193
|
-
let entry = this.
|
|
197
|
+
let entry = this.#subjectKeyPaths.get(targetSubjectId);
|
|
194
198
|
if (!entry) {
|
|
195
199
|
entry = (async () => {
|
|
196
200
|
const subjectInfos = await this.getSubjectInfos();
|
|
197
201
|
const result = new Array();
|
|
198
202
|
let currParentId = targetSubjectId;
|
|
199
203
|
while (currParentId) {
|
|
200
|
-
if (this.
|
|
204
|
+
if (this.#hierarchyConfig.hideRootSubject && currParentId === IModel.rootSubjectId) {
|
|
201
205
|
break;
|
|
202
206
|
}
|
|
203
207
|
const parentInfo = subjectInfos.get(currParentId);
|
|
@@ -208,7 +212,7 @@ export class ModelsTreeIdsCache {
|
|
|
208
212
|
}
|
|
209
213
|
return result.reverse();
|
|
210
214
|
})();
|
|
211
|
-
this.
|
|
215
|
+
this.#subjectKeyPaths.set(targetSubjectId, entry);
|
|
212
216
|
}
|
|
213
217
|
return entry;
|
|
214
218
|
}
|
|
@@ -220,10 +224,10 @@ export class ModelsTreeIdsCache {
|
|
|
220
224
|
m.IsPrivate isModelPrivate,
|
|
221
225
|
MAX(IIF(this.Parent.Id IS NULL, 1, 0)) isRootElementCategory
|
|
222
226
|
FROM BisCore.Model m
|
|
223
|
-
JOIN ${this.
|
|
227
|
+
JOIN ${this.#hierarchyConfig.elementClassSpecification} this ON m.ECInstanceId = this.Model.Id
|
|
224
228
|
GROUP BY modelId, categoryId, isModelPrivate
|
|
225
229
|
`;
|
|
226
|
-
for await (const row of this.
|
|
230
|
+
for await (const row of this.#queryExecutor.createQueryReader({ ecsql: query }, { rowFormat: "ECSqlPropertyNames", limit: "unbounded", restartToken: `${this.#componentName}/${this.#componentId}/model-categories` })) {
|
|
227
231
|
yield { modelId: row.modelId, categoryId: row.categoryId, isModelPrivate: !!row.isModelPrivate, isRootElementCategory: !!row.isRootElementCategory };
|
|
228
232
|
}
|
|
229
233
|
}
|
|
@@ -234,17 +238,17 @@ export class ModelsTreeIdsCache {
|
|
|
234
238
|
pe.Category.Id categoryId,
|
|
235
239
|
pe.Model.Id modelId
|
|
236
240
|
FROM BisCore.Model m
|
|
237
|
-
JOIN ${this.
|
|
241
|
+
JOIN ${this.#hierarchyConfig.elementClassSpecification} pe ON pe.ECInstanceId = m.ModeledElement.Id
|
|
238
242
|
WHERE
|
|
239
243
|
m.IsPrivate = false
|
|
240
|
-
AND m.ECInstanceId IN (SELECT Model.Id FROM ${this.
|
|
244
|
+
AND m.ECInstanceId IN (SELECT Model.Id FROM ${this.#hierarchyConfig.elementClassSpecification})
|
|
241
245
|
`;
|
|
242
|
-
for await (const row of this.
|
|
246
|
+
for await (const row of this.#queryExecutor.createQueryReader({ ecsql: query }, { rowFormat: "ECSqlPropertyNames", limit: "unbounded", restartToken: `${this.#componentName}/${this.#componentId}/modeled-elements` })) {
|
|
243
247
|
yield { modelId: row.modelId, categoryId: row.categoryId, modeledElementId: row.modeledElementId };
|
|
244
248
|
}
|
|
245
249
|
}
|
|
246
250
|
async getModelWithCategoryModeledElements() {
|
|
247
|
-
this
|
|
251
|
+
this.#modelWithCategoryModeledElements ??= (async () => {
|
|
248
252
|
const modelWithCategoryModeledElements = new Map();
|
|
249
253
|
for await (const { modelId, categoryId, modeledElementId } of this.queryModeledElements()) {
|
|
250
254
|
const key = `${modelId}-${categoryId}`;
|
|
@@ -258,10 +262,10 @@ export class ModelsTreeIdsCache {
|
|
|
258
262
|
}
|
|
259
263
|
return modelWithCategoryModeledElements;
|
|
260
264
|
})();
|
|
261
|
-
return this
|
|
265
|
+
return this.#modelWithCategoryModeledElements;
|
|
262
266
|
}
|
|
263
267
|
async getModelInfos() {
|
|
264
|
-
this
|
|
268
|
+
this.#modelInfos ??= (async () => {
|
|
265
269
|
const modelInfos = new Map();
|
|
266
270
|
for await (const { modelId, categoryId, isModelPrivate, isRootElementCategory } of this.queryModelCategories()) {
|
|
267
271
|
const entry = modelInfos.get(modelId);
|
|
@@ -275,7 +279,15 @@ export class ModelsTreeIdsCache {
|
|
|
275
279
|
}
|
|
276
280
|
return modelInfos;
|
|
277
281
|
})();
|
|
278
|
-
return this
|
|
282
|
+
return this.#modelInfos;
|
|
283
|
+
}
|
|
284
|
+
async getAllCategories() {
|
|
285
|
+
const modelInfos = await this.getModelInfos();
|
|
286
|
+
const result = new Set();
|
|
287
|
+
modelInfos.forEach(({ categories }) => {
|
|
288
|
+
categories.forEach((_, categoryId) => result.add(categoryId));
|
|
289
|
+
});
|
|
290
|
+
return result;
|
|
279
291
|
}
|
|
280
292
|
async getModelCategories(modelId) {
|
|
281
293
|
const modelInfos = await this.getModelInfos();
|
|
@@ -302,7 +314,7 @@ export class ModelsTreeIdsCache {
|
|
|
302
314
|
return result;
|
|
303
315
|
}
|
|
304
316
|
async createModelInstanceKeyPaths(modelId) {
|
|
305
|
-
let entry = this.
|
|
317
|
+
let entry = this.#modelKeyPaths.get(modelId);
|
|
306
318
|
if (!entry) {
|
|
307
319
|
entry = (async () => {
|
|
308
320
|
const result = new Array();
|
|
@@ -315,7 +327,7 @@ export class ModelsTreeIdsCache {
|
|
|
315
327
|
}
|
|
316
328
|
return result;
|
|
317
329
|
})();
|
|
318
|
-
this.
|
|
330
|
+
this.#modelKeyPaths.set(modelId, entry);
|
|
319
331
|
}
|
|
320
332
|
return entry;
|
|
321
333
|
}
|
|
@@ -333,12 +345,12 @@ export class ModelsTreeIdsCache {
|
|
|
333
345
|
// we may have thousands of where clauses here, and sending a single query with all of them could take a
|
|
334
346
|
// long time - instead, split it into smaller chunks
|
|
335
347
|
bufferCount(100), mergeMap(async (whereClauses) => {
|
|
336
|
-
const reader = this.
|
|
348
|
+
const reader = this.#queryExecutor.createQueryReader({
|
|
337
349
|
ctes: [
|
|
338
350
|
`
|
|
339
351
|
CategoryElements(id, modelId, categoryId) AS (
|
|
340
352
|
SELECT ECInstanceId, Model.Id, Category.Id
|
|
341
|
-
FROM ${this.
|
|
353
|
+
FROM ${this.#hierarchyConfig.elementClassSpecification}
|
|
342
354
|
WHERE
|
|
343
355
|
Parent.Id IS NULL
|
|
344
356
|
AND (
|
|
@@ -348,7 +360,7 @@ export class ModelsTreeIdsCache {
|
|
|
348
360
|
UNION ALL
|
|
349
361
|
|
|
350
362
|
SELECT c.ECInstanceId, p.modelId, p.categoryId
|
|
351
|
-
FROM ${this.
|
|
363
|
+
FROM ${this.#hierarchyConfig.elementClassSpecification} c
|
|
352
364
|
JOIN CategoryElements p ON c.Parent.Id = p.id
|
|
353
365
|
)
|
|
354
366
|
`,
|
|
@@ -358,7 +370,7 @@ export class ModelsTreeIdsCache {
|
|
|
358
370
|
FROM CategoryElements
|
|
359
371
|
GROUP BY modelId, categoryId
|
|
360
372
|
`,
|
|
361
|
-
}, { rowFormat: "ECSqlPropertyNames", limit: "unbounded" });
|
|
373
|
+
}, { rowFormat: "ECSqlPropertyNames", limit: "unbounded", restartToken: `${this.#componentName}/${this.#componentId}/category-element-counts` });
|
|
362
374
|
const result = new Array();
|
|
363
375
|
for await (const row of reader) {
|
|
364
376
|
result.push({ modelId: row.modelId, categoryId: row.categoryId, elementsCount: row.elementsCount });
|
|
@@ -372,10 +384,10 @@ export class ModelsTreeIdsCache {
|
|
|
372
384
|
}), mergeAll()));
|
|
373
385
|
}
|
|
374
386
|
async getCategoryElementsCount(modelId, categoryId) {
|
|
375
|
-
return this.
|
|
387
|
+
return this.#categoryElementCounts.getCategoryElementsCount(modelId, categoryId);
|
|
376
388
|
}
|
|
377
389
|
async createCategoryInstanceKeyPaths(categoryId) {
|
|
378
|
-
let entry = this.
|
|
390
|
+
let entry = this.#categoryKeyPaths.get(categoryId);
|
|
379
391
|
if (!entry) {
|
|
380
392
|
entry = (async () => {
|
|
381
393
|
const result = new Set();
|
|
@@ -395,7 +407,7 @@ export class ModelsTreeIdsCache {
|
|
|
395
407
|
}
|
|
396
408
|
return categoryPaths;
|
|
397
409
|
})();
|
|
398
|
-
this.
|
|
410
|
+
this.#categoryKeyPaths.set(categoryId, entry);
|
|
399
411
|
}
|
|
400
412
|
return entry;
|
|
401
413
|
}
|
|
@@ -412,34 +424,32 @@ function forEachChildSubject(subjectInfos, parentSubject, cb) {
|
|
|
412
424
|
});
|
|
413
425
|
}
|
|
414
426
|
class ModelCategoryElementsCountCache {
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
this._subscription = this._requestsStream
|
|
422
|
-
.pipe(bufferTime(20), filter((requests) => requests.length > 0), mergeMap(async (requests) => this._loader(requests)), mergeAll())
|
|
427
|
+
#cache = new Map();
|
|
428
|
+
#requestsStream = new Subject();
|
|
429
|
+
#subscription;
|
|
430
|
+
constructor(loader) {
|
|
431
|
+
this.#subscription = this.#requestsStream
|
|
432
|
+
.pipe(bufferTime(20), filter((requests) => requests.length > 0), mergeMap(async (requests) => loader(requests)), mergeAll())
|
|
423
433
|
.subscribe({
|
|
424
434
|
next: ({ modelId, categoryId, elementsCount }) => {
|
|
425
|
-
const subject = this.
|
|
435
|
+
const subject = this.#cache.get(`${modelId}${categoryId}`);
|
|
426
436
|
assert(!!subject);
|
|
427
437
|
subject.next(elementsCount);
|
|
428
438
|
},
|
|
429
439
|
});
|
|
430
440
|
}
|
|
431
441
|
[Symbol.dispose]() {
|
|
432
|
-
this.
|
|
442
|
+
this.#subscription.unsubscribe();
|
|
433
443
|
}
|
|
434
444
|
async getCategoryElementsCount(modelId, categoryId) {
|
|
435
445
|
const cacheKey = `${modelId}${categoryId}`;
|
|
436
|
-
let result = this.
|
|
446
|
+
let result = this.#cache.get(cacheKey);
|
|
437
447
|
if (result !== undefined) {
|
|
438
448
|
return firstValueFrom(result);
|
|
439
449
|
}
|
|
440
450
|
result = new ReplaySubject(1);
|
|
441
|
-
this.
|
|
442
|
-
this.
|
|
451
|
+
this.#cache.set(cacheKey, result);
|
|
452
|
+
this.#requestsStream.next({ modelId, categoryId });
|
|
443
453
|
return firstValueFrom(result);
|
|
444
454
|
}
|
|
445
455
|
}
|
package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModelsTreeIdsCache.js","sourceRoot":"","sources":["../../../../../../../src/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,EAAE,cAAc,EAAE,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACtI,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAsBlD,gBAAgB;AAChB,MAAM,OAAO,kBAAkB;IAWnB;IACA;IAXO,sBAAsB,CAAkC;IACjE,aAAa,CAAoD;IACjE,iBAAiB,CAAiC,CAAC,sFAAsF;IACzI,WAAW,CAAkD;IAC7D,iCAAiC,CAA4C;IAC7E,cAAc,CAA2D;IACzE,gBAAgB,CAAyD;IACzE,iBAAiB,CAA2D;IAEpF,YACU,cAA0C,EAC1C,gBAAkD;QADlD,mBAAc,GAAd,cAAc,CAA4B;QAC1C,qBAAgB,GAAhB,gBAAgB,CAAkC;QAE1D,IAAI,CAAC,sBAAsB,GAAG,IAAI,+BAA+B,CAAC,KAAK,EAAE,KAAK,E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,OAAO,CAAC,QAAQ,CAAC,CAAC,EACpD,QAAQ,EAAE,CACX;aACA,SAAS,CAAC;YACT,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,EAAE,EAAE;gBAC/C,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,OAAO,GAAG,UAAU,EAAE,CAAC,CAAC;gBAC3D,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;gBAClB,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;YAC9B,CAAC;SACF,CAAC,CAAC;IACP,CAAC;IAEM,CAAC,MAAM,CAAC,OAAO,CAAC;QACrB,IAAI,CAAC,aAAa,CAAC,WAAW,EAAE,CAAC;IACnC,CAAC;IAEM,KAAK,CAAC,wBAAwB,CAAC,OAAmB,EAAE,UAAsB;QAC/E,MAAM,QAAQ,GAAG,GAAG,OAAO,GAAG,UAAU,EAAE,CAAC;QAC3C,IAAI,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACvC,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YACzB,OAAO,cAAc,CAAC,MAAM,CAAC,CAAC;QAChC,CAAC;QAED,MAAM,GAAG,IAAI,aAAa,CAAC,CAAC,CAAC,CAAC;QAC9B,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QAClC,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC,CAAC;QACnD,OAAO,cAAc,CAAC,MAAM,CAAC,CAAC;IAChC,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { bufferCount, bufferTime, filter, firstValueFrom, from, map, mergeAll, mergeMap, reduce, ReplaySubject, Subject } from \"rxjs\";\nimport { assert, Id64 } from \"@itwin/core-bentley\";\nimport { IModel } from \"@itwin/core-common\";\nimport { collect } from \"../../common/Rxjs.js\";\nimport { pushToMap } from \"../../common/Utils.js\";\n\nimport type { Subscription } from \"rxjs\";\nimport type { InstanceKey } from \"@itwin/presentation-shared\";\nimport type { ModelsTreeDefinition } from \"../ModelsTreeDefinition.js\";\nimport type { Id64Arg, Id64Array, Id64Set, Id64String } from \"@itwin/core-bentley\";\nimport type { HierarchyNodeIdentifiersPath, LimitingECSqlQueryExecutor } from \"@itwin/presentation-hierarchies\";\n\ninterface SubjectInfo {\n parentSubject: Id64String | undefined;\n hideInHierarchy: boolean;\n childSubjects: Id64Set;\n childModels: Id64Set;\n}\n\ninterface ModelInfo {\n isModelPrivate: boolean;\n categories: Map<Id64String, { isRootElementCategory: boolean }>;\n}\n\ntype ModelsTreeHierarchyConfiguration = ConstructorParameters<typeof ModelsTreeDefinition>[0][\"hierarchyConfig\"];\n\n/** @internal */\nexport class ModelsTreeIdsCache implements Disposable {\n private readonly _categoryElementCounts: ModelCategoryElementsCountCache;\n private _subjectInfos: Promise<Map<Id64String, SubjectInfo>> | undefined;\n private _parentSubjectIds: Promise<Id64Array> | undefined; // the list should contain a subject id if its node should be shown as having children\n private _modelInfos: Promise<Map<Id64String, ModelInfo>> | undefined;\n private _modelWithCategoryModeledElements: Promise<Map<string, Id64Set>> | undefined;\n private _modelKeyPaths: Map<Id64String, Promise<HierarchyNodeIdentifiersPath[]>>;\n private _subjectKeyPaths: Map<Id64String, Promise<HierarchyNodeIdentifiersPath>>;\n private _categoryKeyPaths: Map<Id64String, Promise<HierarchyNodeIdentifiersPath[]>>;\n\n constructor(\n private _queryExecutor: LimitingECSqlQueryExecutor,\n private _hierarchyConfig: ModelsTreeHierarchyConfiguration,\n ) {\n this._categoryElementCounts = new ModelCategoryElementsCountCache(async (input) => this.queryCategoryElementCounts(input));\n this._modelKeyPaths = new Map();\n this._subjectKeyPaths = new Map();\n this._categoryKeyPaths = new Map();\n }\n\n public [Symbol.dispose]() {\n this._categoryElementCounts[Symbol.dispose]();\n }\n\n private async *querySubjects(): AsyncIterableIterator<{ id: Id64String; parentId?: Id64String; targetPartitionId?: Id64String; hideInHierarchy: boolean }> {\n const subjectsQuery = `\n SELECT\n s.ECInstanceId id,\n s.Parent.Id parentId,\n (\n SELECT m.ECInstanceId\n FROM bis.GeometricModel3d m\n WHERE m.ECInstanceId = HexToId(json_extract(s.JsonProperties, '$.Subject.Model.TargetPartition'))\n AND NOT m.IsPrivate\n AND EXISTS (SELECT 1 FROM ${this._hierarchyConfig.elementClassSpecification} WHERE Model.Id = m.ECInstanceId)\n ) targetPartitionId,\n CASE\n WHEN (\n json_extract(s.JsonProperties, '$.Subject.Job.Bridge') IS NOT NULL\n OR json_extract(s.JsonProperties, '$.Subject.Model.Type') = 'Hierarchy'\n ) THEN 1\n ELSE 0\n END hideInHierarchy\n FROM bis.Subject s\n `;\n for await (const row of this._queryExecutor.createQueryReader({ ecsql: subjectsQuery }, { rowFormat: \"ECSqlPropertyNames\", limit: \"unbounded\" })) {\n yield { id: row.id, parentId: row.parentId, targetPartitionId: row.targetPartitionId, hideInHierarchy: !!row.hideInHierarchy };\n }\n }\n\n private async *queryModels(): AsyncIterableIterator<{ id: Id64String; parentId: Id64String }> {\n const modelsQuery = `\n SELECT p.ECInstanceId id, p.Parent.Id parentId\n FROM bis.InformationPartitionElement p\n INNER JOIN bis.GeometricModel3d m ON m.ModeledElement.Id = p.ECInstanceId\n WHERE\n NOT m.IsPrivate\n ${this._hierarchyConfig.showEmptyModels ? \"\" : `AND EXISTS (SELECT 1 FROM ${this._hierarchyConfig.elementClassSpecification} WHERE Model.Id = m.ECInstanceId)`}\n `;\n for await (const row of this._queryExecutor.createQueryReader({ ecsql: modelsQuery }, { rowFormat: \"ECSqlPropertyNames\", limit: \"unbounded\" })) {\n yield { id: row.id, parentId: row.parentId };\n }\n }\n\n private async getSubjectInfos() {\n this._subjectInfos ??= (async () => {\n const [subjectInfos, targetPartitionSubjects] = await Promise.all([\n (async () => {\n const result = new Map<Id64String, SubjectInfo>();\n for await (const subject of this.querySubjects()) {\n const subjectInfo: SubjectInfo = {\n parentSubject: subject.parentId,\n hideInHierarchy: subject.hideInHierarchy,\n childSubjects: new Set(),\n childModels: new Set(),\n };\n if (subject.targetPartitionId) {\n subjectInfo.childModels.add(subject.targetPartitionId);\n }\n result.set(subject.id, subjectInfo);\n }\n return result;\n })(),\n (async () => {\n const result = new Map<Id64String, Set<Id64String>>();\n for await (const model of this.queryModels()) {\n pushToMap(result, model.id, model.parentId);\n }\n return result;\n })(),\n ]);\n\n for (const [subjectId, { parentSubject: parentSubjectId }] of subjectInfos.entries()) {\n if (parentSubjectId) {\n const parentSubjectInfo = subjectInfos.get(parentSubjectId);\n assert(!!parentSubjectInfo);\n parentSubjectInfo.childSubjects.add(subjectId);\n }\n }\n\n for (const [partitionId, subjectIds] of targetPartitionSubjects) {\n subjectIds.forEach((subjectId) => {\n const subjectInfo = subjectInfos.get(subjectId);\n assert(!!subjectInfo);\n subjectInfo.childModels.add(partitionId);\n });\n }\n\n return subjectInfos;\n })();\n return this._subjectInfos;\n }\n\n /** Returns ECInstanceIDs of Subjects that either have direct Model or at least one child Subject with a Model. */\n public async getParentSubjectIds(): Promise<Id64String[]> {\n this._parentSubjectIds ??= (async () => {\n const subjectInfos = await this.getSubjectInfos();\n const parentSubjectIds = new Set<Id64String>();\n subjectInfos.forEach((subjectInfo, subjectId) => {\n if (subjectInfo.childModels.size > 0) {\n parentSubjectIds.add(subjectId);\n let currParentId = subjectInfo.parentSubject;\n while (currParentId) {\n parentSubjectIds.add(currParentId);\n currParentId = subjectInfos.get(currParentId)?.parentSubject;\n }\n }\n });\n return [...parentSubjectIds];\n })();\n return this._parentSubjectIds;\n }\n\n /**\n * Returns child subjects of the specified parent subjects as they're displayed in the hierarchy - taking into\n * account `hideInHierarchy` flag.\n */\n public async getChildSubjectIds(parentSubjectIds: Id64String[]): Promise<Id64String[]> {\n const childSubjectIds = new Array<Id64String>();\n const subjectInfos = await this.getSubjectInfos();\n parentSubjectIds.forEach((subjectId) => {\n forEachChildSubject(subjectInfos, subjectId, (childSubjectId, childSubjectInfo) => {\n if (!childSubjectInfo.hideInHierarchy) {\n childSubjectIds.push(childSubjectId);\n return \"break\";\n }\n return \"continue\";\n });\n });\n return childSubjectIds;\n }\n\n /** Returns ECInstanceIDs of all Models under specific parent Subjects, including their child Subjects, etc. */\n public async getSubjectModelIds(subjectIds: Id64Array): Promise<Id64Array> {\n const subjectInfos = await this.getSubjectInfos();\n const subjectStack = [...subjectIds];\n const result = new Array<Id64String>();\n while (true) {\n const subjectId = subjectStack.pop();\n if (subjectId === undefined) {\n break;\n }\n const subjectInfo = subjectInfos.get(subjectId);\n if (!subjectInfo) {\n continue;\n }\n result.push(...subjectInfo.childModels);\n subjectStack.push(...subjectInfo.childSubjects);\n }\n return result;\n }\n\n /** Returns ECInstanceIDs of Models under specific parent Subjects as they are displayed in the hierarchy. */\n public async getChildSubjectModelIds(parentSubjectIds: Id64String[]): Promise<Id64String[]> {\n const subjectInfos = await this.getSubjectInfos();\n\n const hiddenSubjectIds = new Array<Id64String>();\n parentSubjectIds.forEach((subjectId) => {\n forEachChildSubject(subjectInfos, subjectId, (childSubjectId, childSubjectInfo) => {\n if (childSubjectInfo.hideInHierarchy) {\n hiddenSubjectIds.push(childSubjectId);\n return \"continue\";\n }\n return \"break\";\n });\n });\n\n const modelIds = new Array<Id64String>();\n [...parentSubjectIds, ...hiddenSubjectIds].forEach((subjectId) => {\n const subjectInfo = subjectInfos.get(subjectId);\n subjectInfo && modelIds.push(...subjectInfo.childModels);\n });\n return modelIds;\n }\n\n public async createSubjectInstanceKeysPath(targetSubjectId: Id64String): Promise<HierarchyNodeIdentifiersPath> {\n let entry = this._subjectKeyPaths.get(targetSubjectId);\n if (!entry) {\n entry = (async () => {\n const subjectInfos = await this.getSubjectInfos();\n const result = new Array<InstanceKey>();\n let currParentId: Id64String | undefined = targetSubjectId;\n while (currParentId) {\n if (this._hierarchyConfig.hideRootSubject && currParentId === IModel.rootSubjectId) {\n break;\n }\n const parentInfo = subjectInfos.get(currParentId);\n if (!parentInfo?.hideInHierarchy) {\n result.push({ className: \"BisCore.Subject\", id: currParentId });\n }\n currParentId = parentInfo?.parentSubject;\n }\n return result.reverse();\n })();\n this._subjectKeyPaths.set(targetSubjectId, entry);\n }\n return entry;\n }\n\n private async *queryModelCategories(): AsyncIterableIterator<{\n modelId: Id64String;\n categoryId: Id64String;\n isModelPrivate: boolean;\n isRootElementCategory: boolean;\n }> {\n const query = `\n SELECT\n this.Model.Id modelId,\n this.Category.Id categoryId,\n m.IsPrivate isModelPrivate,\n MAX(IIF(this.Parent.Id IS NULL, 1, 0)) isRootElementCategory\n FROM BisCore.Model m\n JOIN ${this._hierarchyConfig.elementClassSpecification} this ON m.ECInstanceId = this.Model.Id\n GROUP BY modelId, categoryId, isModelPrivate\n `;\n for await (const row of this._queryExecutor.createQueryReader({ ecsql: query }, { rowFormat: \"ECSqlPropertyNames\", limit: \"unbounded\" })) {\n yield { modelId: row.modelId, categoryId: row.categoryId, isModelPrivate: !!row.isModelPrivate, isRootElementCategory: !!row.isRootElementCategory };\n }\n }\n\n private async *queryModeledElements() {\n const query = `\n SELECT\n pe.ECInstanceId modeledElementId,\n pe.Category.Id categoryId,\n pe.Model.Id modelId\n FROM BisCore.Model m\n JOIN ${this._hierarchyConfig.elementClassSpecification} pe ON pe.ECInstanceId = m.ModeledElement.Id\n WHERE\n m.IsPrivate = false\n AND m.ECInstanceId IN (SELECT Model.Id FROM ${this._hierarchyConfig.elementClassSpecification})\n `;\n for await (const row of this._queryExecutor.createQueryReader({ ecsql: query }, { rowFormat: \"ECSqlPropertyNames\", limit: \"unbounded\" })) {\n yield { modelId: row.modelId, categoryId: row.categoryId, modeledElementId: row.modeledElementId };\n }\n }\n\n private async getModelWithCategoryModeledElements() {\n this._modelWithCategoryModeledElements ??= (async () => {\n const modelWithCategoryModeledElements = new Map<Id64String, Id64Set>();\n for await (const { modelId, categoryId, modeledElementId } of this.queryModeledElements()) {\n const key = `${modelId}-${categoryId}`;\n const entry = modelWithCategoryModeledElements.get(key);\n if (entry === undefined) {\n modelWithCategoryModeledElements.set(key, new Set([modeledElementId]));\n } else {\n entry.add(modeledElementId);\n }\n }\n return modelWithCategoryModeledElements;\n })();\n return this._modelWithCategoryModeledElements;\n }\n\n private async getModelInfos() {\n this._modelInfos ??= (async () => {\n const modelInfos = new Map<Id64String, { categories: Map<Id64String, { isRootElementCategory: boolean }>; isModelPrivate: boolean }>();\n for await (const { modelId, categoryId, isModelPrivate, isRootElementCategory } of this.queryModelCategories()) {\n const entry = modelInfos.get(modelId);\n if (entry) {\n entry.categories.set(categoryId, { isRootElementCategory });\n entry.isModelPrivate = isModelPrivate;\n } else {\n modelInfos.set(modelId, { categories: new Map([[categoryId, { isRootElementCategory }]]), isModelPrivate });\n }\n }\n return modelInfos;\n })();\n return this._modelInfos;\n }\n\n public async getModelCategories(modelId: Id64String): Promise<Id64Array> {\n const modelInfos = await this.getModelInfos();\n const categories = modelInfos.get(modelId)?.categories.keys();\n return categories ? [...categories] : [];\n }\n\n public async hasSubModel(elementId: Id64String): Promise<boolean> {\n const modelInfos = await this.getModelInfos();\n const modeledElementInfo = modelInfos.get(elementId);\n if (!modeledElementInfo) {\n return false;\n }\n return !modeledElementInfo.isModelPrivate;\n }\n\n public async getCategoriesModeledElements(modelId: Id64String, categoryIds: Id64Arg): Promise<Id64Array> {\n const modelWithCategoryModeledElements = await this.getModelWithCategoryModeledElements();\n const result = new Array<Id64String>();\n for (const categoryId of Id64.iterable(categoryIds)) {\n const entry = modelWithCategoryModeledElements.get(`${modelId}-${categoryId}`);\n if (entry !== undefined) {\n result.push(...entry);\n }\n }\n return result;\n }\n\n public async createModelInstanceKeyPaths(modelId: Id64String): Promise<HierarchyNodeIdentifiersPath[]> {\n let entry = this._modelKeyPaths.get(modelId);\n if (!entry) {\n entry = (async () => {\n const result = new Array<HierarchyNodeIdentifiersPath>();\n const subjectInfos = (await this.getSubjectInfos()).entries();\n for (const [modelSubjectId, subjectInfo] of subjectInfos) {\n if (subjectInfo.childModels.has(modelId)) {\n const subjectPath = await this.createSubjectInstanceKeysPath(modelSubjectId);\n result.push([...subjectPath, { className: \"BisCore.GeometricModel3d\", id: modelId }]);\n }\n }\n return result;\n })();\n\n this._modelKeyPaths.set(modelId, entry);\n }\n return entry;\n }\n\n private async queryCategoryElementCounts(\n input: Array<{ modelId: Id64String; categoryId: Id64String }>,\n ): Promise<Array<{ modelId: Id64String; categoryId: Id64String; elementsCount: number }>> {\n return collect(\n from(input).pipe(\n reduce((acc, { modelId, categoryId }) => {\n const entry = acc.get(modelId);\n if (!entry) {\n acc.set(modelId, new Set([categoryId]));\n } else {\n entry.add(categoryId);\n }\n return acc;\n }, new Map<Id64String, Id64Set>()),\n mergeMap((modelCategoryMap) => modelCategoryMap.entries()),\n map(([modelId, categoryIds]) => `Model.Id = ${modelId} AND Category.Id IN (${[...categoryIds].join(\", \")})`),\n // we may have thousands of where clauses here, and sending a single query with all of them could take a\n // long time - instead, split it into smaller chunks\n bufferCount(100),\n mergeMap(async (whereClauses) => {\n const reader = this._queryExecutor.createQueryReader(\n {\n ctes: [\n `\n CategoryElements(id, modelId, categoryId) AS (\n SELECT ECInstanceId, Model.Id, Category.Id\n FROM ${this._hierarchyConfig.elementClassSpecification}\n WHERE\n Parent.Id IS NULL\n AND (\n ${whereClauses.join(\" OR \")}\n )\n\n UNION ALL\n\n SELECT c.ECInstanceId, p.modelId, p.categoryId\n FROM ${this._hierarchyConfig.elementClassSpecification} c\n JOIN CategoryElements p ON c.Parent.Id = p.id\n )\n `,\n ],\n ecsql: `\n SELECT modelId, categoryId, COUNT(id) elementsCount\n FROM CategoryElements\n GROUP BY modelId, categoryId\n `,\n },\n { rowFormat: \"ECSqlPropertyNames\", limit: \"unbounded\" },\n );\n\n const result = new Array<{ modelId: Id64String; categoryId: Id64String; elementsCount: number }>();\n for await (const row of reader) {\n result.push({ modelId: row.modelId, categoryId: row.categoryId, elementsCount: row.elementsCount });\n }\n\n input.forEach(({ modelId, categoryId }) => {\n if (!result.some((queriedResult) => queriedResult.categoryId === categoryId && queriedResult.modelId === modelId)) {\n result.push({ categoryId, modelId, elementsCount: 0 });\n }\n });\n\n return result;\n }),\n mergeAll(),\n ),\n );\n }\n\n public async getCategoryElementsCount(modelId: Id64String, categoryId: Id64String): Promise<number> {\n return this._categoryElementCounts.getCategoryElementsCount(modelId, categoryId);\n }\n\n public async createCategoryInstanceKeyPaths(categoryId: Id64String): Promise<HierarchyNodeIdentifiersPath[]> {\n let entry = this._categoryKeyPaths.get(categoryId);\n if (!entry) {\n entry = (async () => {\n const result = new Set<Id64String>();\n const modelInfos = await this.getModelInfos();\n modelInfos?.forEach((modelInfo, modelId) => {\n const categoryEntry = modelInfo.categories.get(categoryId);\n if (categoryEntry?.isRootElementCategory) {\n result.add(modelId);\n }\n });\n\n const categoryPaths = new Array<HierarchyNodeIdentifiersPath>();\n for (const categoryModelId of [...result]) {\n const modelPaths = await this.createModelInstanceKeyPaths(categoryModelId);\n for (const modelPath of modelPaths) {\n categoryPaths.push([...modelPath, { className: \"BisCore.SpatialCategory\", id: categoryId }]);\n }\n }\n return categoryPaths;\n })();\n this._categoryKeyPaths.set(categoryId, entry);\n }\n return entry;\n }\n}\n\nfunction forEachChildSubject(\n subjectInfos: Map<Id64String, SubjectInfo>,\n parentSubject: Id64String | SubjectInfo,\n cb: (childSubjectId: Id64String, childSubjectInfo: SubjectInfo) => \"break\" | \"continue\",\n) {\n const parentSubjectInfo = typeof parentSubject === \"string\" ? subjectInfos.get(parentSubject) : parentSubject;\n parentSubjectInfo &&\n parentSubjectInfo.childSubjects.forEach((childSubjectId) => {\n const childSubjectInfo = subjectInfos.get(childSubjectId)!;\n if (cb(childSubjectId, childSubjectInfo) === \"break\") {\n return;\n }\n forEachChildSubject(subjectInfos, childSubjectInfo, cb);\n });\n}\n\nclass ModelCategoryElementsCountCache {\n private _cache = new Map<string, Subject<number>>();\n private _requestsStream = new Subject<{ modelId: Id64String; categoryId: Id64String }>();\n private _subscription: Subscription;\n\n public constructor(\n private _loader: (\n input: Array<{ modelId: Id64String; categoryId: Id64String }>,\n ) => Promise<Array<{ modelId: Id64String; categoryId: Id64String; elementsCount: number }>>,\n ) {\n this._subscription = this._requestsStream\n .pipe(\n bufferTime(20),\n filter((requests) => requests.length > 0),\n mergeMap(async (requests) => this._loader(requests)),\n mergeAll(),\n )\n .subscribe({\n next: ({ modelId, categoryId, elementsCount }) => {\n const subject = this._cache.get(`${modelId}${categoryId}`);\n assert(!!subject);\n subject.next(elementsCount);\n },\n });\n }\n\n public [Symbol.dispose]() {\n this._subscription.unsubscribe();\n }\n\n public async getCategoryElementsCount(modelId: Id64String, categoryId: Id64String): Promise<number> {\n const cacheKey = `${modelId}${categoryId}`;\n let result = this._cache.get(cacheKey);\n if (result !== undefined) {\n return firstValueFrom(result);\n }\n\n result = new ReplaySubject(1);\n this._cache.set(cacheKey, result);\n this._requestsStream.next({ modelId, categoryId });\n return firstValueFrom(result);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ModelsTreeIdsCache.js","sourceRoot":"","sources":["../../../../../../../src/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,EAAE,cAAc,EAAE,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACtI,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AA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------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { bufferCount, bufferTime, filter, firstValueFrom, from, map, mergeAll, mergeMap, reduce, ReplaySubject, Subject } from \"rxjs\";\nimport { assert, Guid, Id64 } from \"@itwin/core-bentley\";\nimport { IModel } from \"@itwin/core-common\";\nimport { collect } from \"../../common/Rxjs.js\";\nimport { pushToMap } from \"../../common/Utils.js\";\n\nimport type { Subscription } from \"rxjs\";\nimport type { GuidString, Id64Arg, Id64Array, Id64Set, Id64String } from \"@itwin/core-bentley\";\nimport type { InstanceKey } from \"@itwin/presentation-shared\";\nimport type { HierarchyNodeIdentifiersPath, LimitingECSqlQueryExecutor } from \"@itwin/presentation-hierarchies\";\nimport type { ModelsTreeDefinition } from \"../ModelsTreeDefinition.js\";\n\ninterface SubjectInfo {\n parentSubject: Id64String | undefined;\n hideInHierarchy: boolean;\n childSubjects: Id64Set;\n childModels: Id64Set;\n}\n\ninterface ModelInfo {\n isModelPrivate: boolean;\n categories: Map<Id64String, { isRootElementCategory: boolean }>;\n}\n\ntype ModelsTreeHierarchyConfiguration = ConstructorParameters<typeof ModelsTreeDefinition>[0][\"hierarchyConfig\"];\n\n/** @internal */\nexport class ModelsTreeIdsCache implements Disposable {\n readonly #categoryElementCounts: ModelCategoryElementsCountCache;\n #subjectInfos: Promise<Map<Id64String, SubjectInfo>> | undefined;\n #parentSubjectIds: Promise<Id64Array> | undefined; // the list should contain a subject id if its node should be shown as having children\n #modelInfos: Promise<Map<Id64String, ModelInfo>> | undefined;\n #modelWithCategoryModeledElements: Promise<Map<string, Id64Set>> | undefined;\n #modelKeyPaths: Map<Id64String, Promise<HierarchyNodeIdentifiersPath[]>>;\n #subjectKeyPaths: Map<Id64String, Promise<HierarchyNodeIdentifiersPath>>;\n #categoryKeyPaths: Map<Id64String, Promise<HierarchyNodeIdentifiersPath[]>>;\n #queryExecutor: LimitingECSqlQueryExecutor;\n #hierarchyConfig: ModelsTreeHierarchyConfiguration;\n #componentId: GuidString;\n #componentName: string;\n\n constructor(queryExecutor: LimitingECSqlQueryExecutor, hierarchyConfig: ModelsTreeHierarchyConfiguration, componentId?: GuidString) {\n this.#hierarchyConfig = hierarchyConfig;\n this.#queryExecutor = queryExecutor;\n this.#categoryElementCounts = new ModelCategoryElementsCountCache(async (input) => this.queryCategoryElementCounts(input));\n this.#modelKeyPaths = new Map();\n this.#subjectKeyPaths = new Map();\n this.#categoryKeyPaths = new Map();\n this.#componentId = componentId ?? Guid.createValue();\n this.#componentName = \"ModelsTreeIdsCache\";\n }\n\n public [Symbol.dispose]() {\n this.#categoryElementCounts[Symbol.dispose]();\n }\n\n private async *querySubjects(): AsyncIterableIterator<{ id: Id64String; parentId?: Id64String; targetPartitionId?: Id64String; hideInHierarchy: boolean }> {\n const subjectsQuery = `\n SELECT\n s.ECInstanceId id,\n s.Parent.Id parentId,\n (\n SELECT m.ECInstanceId\n FROM bis.GeometricModel3d m\n WHERE m.ECInstanceId = HexToId(json_extract(s.JsonProperties, '$.Subject.Model.TargetPartition'))\n AND NOT m.IsPrivate\n AND EXISTS (SELECT 1 FROM ${this.#hierarchyConfig.elementClassSpecification} WHERE Model.Id = m.ECInstanceId)\n ) targetPartitionId,\n CASE\n WHEN (\n json_extract(s.JsonProperties, '$.Subject.Job.Bridge') IS NOT NULL\n OR json_extract(s.JsonProperties, '$.Subject.Model.Type') = 'Hierarchy'\n ) THEN 1\n ELSE 0\n END hideInHierarchy\n FROM bis.Subject s\n `;\n for await (const row of this.#queryExecutor.createQueryReader(\n { ecsql: subjectsQuery },\n { rowFormat: \"ECSqlPropertyNames\", limit: \"unbounded\", restartToken: `${this.#componentName}/${this.#componentId}/subjects` },\n )) {\n yield { id: row.id, parentId: row.parentId, targetPartitionId: row.targetPartitionId, hideInHierarchy: !!row.hideInHierarchy };\n }\n }\n\n private async *queryModels(): AsyncIterableIterator<{ id: Id64String; parentId: Id64String }> {\n const modelsQuery = `\n SELECT p.ECInstanceId id, p.Parent.Id parentId\n FROM bis.InformationPartitionElement p\n INNER JOIN bis.GeometricModel3d m ON m.ModeledElement.Id = p.ECInstanceId\n WHERE\n NOT m.IsPrivate\n ${this.#hierarchyConfig.showEmptyModels ? \"\" : `AND EXISTS (SELECT 1 FROM ${this.#hierarchyConfig.elementClassSpecification} WHERE Model.Id = m.ECInstanceId)`}\n `;\n for await (const row of this.#queryExecutor.createQueryReader(\n { ecsql: modelsQuery },\n { rowFormat: \"ECSqlPropertyNames\", limit: \"unbounded\", restartToken: `${this.#componentName}/${this.#componentId}/models` },\n )) {\n yield { id: row.id, parentId: row.parentId };\n }\n }\n\n private async getSubjectInfos() {\n this.#subjectInfos ??= (async () => {\n const [subjectInfos, targetPartitionSubjects] = await Promise.all([\n (async () => {\n const result = new Map<Id64String, SubjectInfo>();\n for await (const subject of this.querySubjects()) {\n const subjectInfo: SubjectInfo = {\n parentSubject: subject.parentId,\n hideInHierarchy: subject.hideInHierarchy,\n childSubjects: new Set(),\n childModels: new Set(),\n };\n if (subject.targetPartitionId) {\n subjectInfo.childModels.add(subject.targetPartitionId);\n }\n result.set(subject.id, subjectInfo);\n }\n return result;\n })(),\n (async () => {\n const result = new Map<Id64String, Set<Id64String>>();\n for await (const model of this.queryModels()) {\n pushToMap(result, model.id, model.parentId);\n }\n return result;\n })(),\n ]);\n\n for (const [subjectId, { parentSubject: parentSubjectId }] of subjectInfos.entries()) {\n if (parentSubjectId) {\n const parentSubjectInfo = subjectInfos.get(parentSubjectId);\n assert(!!parentSubjectInfo);\n parentSubjectInfo.childSubjects.add(subjectId);\n }\n }\n\n for (const [partitionId, subjectIds] of targetPartitionSubjects) {\n subjectIds.forEach((subjectId) => {\n const subjectInfo = subjectInfos.get(subjectId);\n assert(!!subjectInfo);\n subjectInfo.childModels.add(partitionId);\n });\n }\n\n return subjectInfos;\n })();\n return this.#subjectInfos;\n }\n\n /** Returns ECInstanceIDs of Subjects that either have direct Model or at least one child Subject with a Model. */\n public async getParentSubjectIds(): Promise<Id64String[]> {\n this.#parentSubjectIds ??= (async () => {\n const subjectInfos = await this.getSubjectInfos();\n const parentSubjectIds = new Set<Id64String>();\n subjectInfos.forEach((subjectInfo, subjectId) => {\n if (subjectInfo.childModels.size > 0) {\n parentSubjectIds.add(subjectId);\n let currParentId = subjectInfo.parentSubject;\n while (currParentId) {\n parentSubjectIds.add(currParentId);\n currParentId = subjectInfos.get(currParentId)?.parentSubject;\n }\n }\n });\n return [...parentSubjectIds];\n })();\n return this.#parentSubjectIds;\n }\n\n /**\n * Returns child subjects of the specified parent subjects as they're displayed in the hierarchy - taking into\n * account `hideInHierarchy` flag.\n */\n public async getChildSubjectIds(parentSubjectIds: Id64String[]): Promise<Id64String[]> {\n const childSubjectIds = new Array<Id64String>();\n const subjectInfos = await this.getSubjectInfos();\n parentSubjectIds.forEach((subjectId) => {\n forEachChildSubject(subjectInfos, subjectId, (childSubjectId, childSubjectInfo) => {\n if (!childSubjectInfo.hideInHierarchy) {\n childSubjectIds.push(childSubjectId);\n return \"break\";\n }\n return \"continue\";\n });\n });\n return childSubjectIds;\n }\n\n /** Returns ECInstanceIDs of all Models under specific parent Subjects, including their child Subjects, etc. */\n public async getSubjectModelIds(subjectIds: Id64Array): Promise<Id64Array> {\n const subjectInfos = await this.getSubjectInfos();\n const subjectStack = [...subjectIds];\n const result = new Array<Id64String>();\n while (true) {\n const subjectId = subjectStack.pop();\n if (subjectId === undefined) {\n break;\n }\n const subjectInfo = subjectInfos.get(subjectId);\n if (!subjectInfo) {\n continue;\n }\n result.push(...subjectInfo.childModels);\n subjectStack.push(...subjectInfo.childSubjects);\n }\n return result;\n }\n\n /** Returns ECInstanceIDs of Models under specific parent Subjects as they are displayed in the hierarchy. */\n public async getChildSubjectModelIds(parentSubjectIds: Id64String[]): Promise<Id64String[]> {\n const subjectInfos = await this.getSubjectInfos();\n\n const hiddenSubjectIds = new Array<Id64String>();\n parentSubjectIds.forEach((subjectId) => {\n forEachChildSubject(subjectInfos, subjectId, (childSubjectId, childSubjectInfo) => {\n if (childSubjectInfo.hideInHierarchy) {\n hiddenSubjectIds.push(childSubjectId);\n return \"continue\";\n }\n return \"break\";\n });\n });\n\n const modelIds = new Array<Id64String>();\n [...parentSubjectIds, ...hiddenSubjectIds].forEach((subjectId) => {\n const subjectInfo = subjectInfos.get(subjectId);\n subjectInfo && modelIds.push(...subjectInfo.childModels);\n });\n return modelIds;\n }\n\n public async createSubjectInstanceKeysPath(targetSubjectId: Id64String): Promise<HierarchyNodeIdentifiersPath> {\n let entry = this.#subjectKeyPaths.get(targetSubjectId);\n if (!entry) {\n entry = (async () => {\n const subjectInfos = await this.getSubjectInfos();\n const result = new Array<InstanceKey>();\n let currParentId: Id64String | undefined = targetSubjectId;\n while (currParentId) {\n if (this.#hierarchyConfig.hideRootSubject && currParentId === IModel.rootSubjectId) {\n break;\n }\n const parentInfo = subjectInfos.get(currParentId);\n if (!parentInfo?.hideInHierarchy) {\n result.push({ className: \"BisCore.Subject\", id: currParentId });\n }\n currParentId = parentInfo?.parentSubject;\n }\n return result.reverse();\n })();\n this.#subjectKeyPaths.set(targetSubjectId, entry);\n }\n return entry;\n }\n\n private async *queryModelCategories(): AsyncIterableIterator<{\n modelId: Id64String;\n categoryId: Id64String;\n isModelPrivate: boolean;\n isRootElementCategory: boolean;\n }> {\n const query = `\n SELECT\n this.Model.Id modelId,\n this.Category.Id categoryId,\n m.IsPrivate isModelPrivate,\n MAX(IIF(this.Parent.Id IS NULL, 1, 0)) isRootElementCategory\n FROM BisCore.Model m\n JOIN ${this.#hierarchyConfig.elementClassSpecification} this ON m.ECInstanceId = this.Model.Id\n GROUP BY modelId, categoryId, isModelPrivate\n `;\n for await (const row of this.#queryExecutor.createQueryReader(\n { ecsql: query },\n { rowFormat: \"ECSqlPropertyNames\", limit: \"unbounded\", restartToken: `${this.#componentName}/${this.#componentId}/model-categories` },\n )) {\n yield { modelId: row.modelId, categoryId: row.categoryId, isModelPrivate: !!row.isModelPrivate, isRootElementCategory: !!row.isRootElementCategory };\n }\n }\n\n private async *queryModeledElements() {\n const query = `\n SELECT\n pe.ECInstanceId modeledElementId,\n pe.Category.Id categoryId,\n pe.Model.Id modelId\n FROM BisCore.Model m\n JOIN ${this.#hierarchyConfig.elementClassSpecification} pe ON pe.ECInstanceId = m.ModeledElement.Id\n WHERE\n m.IsPrivate = false\n AND m.ECInstanceId IN (SELECT Model.Id FROM ${this.#hierarchyConfig.elementClassSpecification})\n `;\n for await (const row of this.#queryExecutor.createQueryReader(\n { ecsql: query },\n { rowFormat: \"ECSqlPropertyNames\", limit: \"unbounded\", restartToken: `${this.#componentName}/${this.#componentId}/modeled-elements` },\n )) {\n yield { modelId: row.modelId, categoryId: row.categoryId, modeledElementId: row.modeledElementId };\n }\n }\n\n private async getModelWithCategoryModeledElements() {\n this.#modelWithCategoryModeledElements ??= (async () => {\n const modelWithCategoryModeledElements = new Map<Id64String, Id64Set>();\n for await (const { modelId, categoryId, modeledElementId } of this.queryModeledElements()) {\n const key = `${modelId}-${categoryId}`;\n const entry = modelWithCategoryModeledElements.get(key);\n if (entry === undefined) {\n modelWithCategoryModeledElements.set(key, new Set([modeledElementId]));\n } else {\n entry.add(modeledElementId);\n }\n }\n return modelWithCategoryModeledElements;\n })();\n return this.#modelWithCategoryModeledElements;\n }\n\n private async getModelInfos() {\n this.#modelInfos ??= (async () => {\n const modelInfos = new Map<Id64String, { categories: Map<Id64String, { isRootElementCategory: boolean }>; isModelPrivate: boolean }>();\n for await (const { modelId, categoryId, isModelPrivate, isRootElementCategory } of this.queryModelCategories()) {\n const entry = modelInfos.get(modelId);\n if (entry) {\n entry.categories.set(categoryId, { isRootElementCategory });\n entry.isModelPrivate = isModelPrivate;\n } else {\n modelInfos.set(modelId, { categories: new Map([[categoryId, { isRootElementCategory }]]), isModelPrivate });\n }\n }\n return modelInfos;\n })();\n return this.#modelInfos;\n }\n\n public async getAllCategories(): Promise<Id64Set> {\n const modelInfos = await this.getModelInfos();\n const result = new Set<Id64String>();\n modelInfos.forEach(({ categories }) => {\n categories.forEach((_, categoryId) => result.add(categoryId));\n });\n return result;\n }\n\n public async getModelCategories(modelId: Id64String): Promise<Id64Array> {\n const modelInfos = await this.getModelInfos();\n const categories = modelInfos.get(modelId)?.categories.keys();\n return categories ? [...categories] : [];\n }\n\n public async hasSubModel(elementId: Id64String): Promise<boolean> {\n const modelInfos = await this.getModelInfos();\n const modeledElementInfo = modelInfos.get(elementId);\n if (!modeledElementInfo) {\n return false;\n }\n return !modeledElementInfo.isModelPrivate;\n }\n\n public async getCategoriesModeledElements(modelId: Id64String, categoryIds: Id64Arg): Promise<Id64Array> {\n const modelWithCategoryModeledElements = await this.getModelWithCategoryModeledElements();\n const result = new Array<Id64String>();\n for (const categoryId of Id64.iterable(categoryIds)) {\n const entry = modelWithCategoryModeledElements.get(`${modelId}-${categoryId}`);\n if (entry !== undefined) {\n result.push(...entry);\n }\n }\n return result;\n }\n\n public async createModelInstanceKeyPaths(modelId: Id64String): Promise<HierarchyNodeIdentifiersPath[]> {\n let entry = this.#modelKeyPaths.get(modelId);\n if (!entry) {\n entry = (async () => {\n const result = new Array<HierarchyNodeIdentifiersPath>();\n const subjectInfos = (await this.getSubjectInfos()).entries();\n for (const [modelSubjectId, subjectInfo] of subjectInfos) {\n if (subjectInfo.childModels.has(modelId)) {\n const subjectPath = await this.createSubjectInstanceKeysPath(modelSubjectId);\n result.push([...subjectPath, { className: \"BisCore.GeometricModel3d\", id: modelId }]);\n }\n }\n return result;\n })();\n\n this.#modelKeyPaths.set(modelId, entry);\n }\n return entry;\n }\n\n private async queryCategoryElementCounts(\n input: Array<{ modelId: Id64String; categoryId: Id64String }>,\n ): Promise<Array<{ modelId: Id64String; categoryId: Id64String; elementsCount: number }>> {\n return collect(\n from(input).pipe(\n reduce((acc, { modelId, categoryId }) => {\n const entry = acc.get(modelId);\n if (!entry) {\n acc.set(modelId, new Set([categoryId]));\n } else {\n entry.add(categoryId);\n }\n return acc;\n }, new Map<Id64String, Id64Set>()),\n mergeMap((modelCategoryMap) => modelCategoryMap.entries()),\n map(([modelId, categoryIds]) => `Model.Id = ${modelId} AND Category.Id IN (${[...categoryIds].join(\", \")})`),\n // we may have thousands of where clauses here, and sending a single query with all of them could take a\n // long time - instead, split it into smaller chunks\n bufferCount(100),\n mergeMap(async (whereClauses) => {\n const reader = this.#queryExecutor.createQueryReader(\n {\n ctes: [\n `\n CategoryElements(id, modelId, categoryId) AS (\n SELECT ECInstanceId, Model.Id, Category.Id\n FROM ${this.#hierarchyConfig.elementClassSpecification}\n WHERE\n Parent.Id IS NULL\n AND (\n ${whereClauses.join(\" OR \")}\n )\n\n UNION ALL\n\n SELECT c.ECInstanceId, p.modelId, p.categoryId\n FROM ${this.#hierarchyConfig.elementClassSpecification} c\n JOIN CategoryElements p ON c.Parent.Id = p.id\n )\n `,\n ],\n ecsql: `\n SELECT modelId, categoryId, COUNT(id) elementsCount\n FROM CategoryElements\n GROUP BY modelId, categoryId\n `,\n },\n { rowFormat: \"ECSqlPropertyNames\", limit: \"unbounded\", restartToken: `${this.#componentName}/${this.#componentId}/category-element-counts` },\n );\n\n const result = new Array<{ modelId: Id64String; categoryId: Id64String; elementsCount: number }>();\n for await (const row of reader) {\n result.push({ modelId: row.modelId, categoryId: row.categoryId, elementsCount: row.elementsCount });\n }\n\n input.forEach(({ modelId, categoryId }) => {\n if (!result.some((queriedResult) => queriedResult.categoryId === categoryId && queriedResult.modelId === modelId)) {\n result.push({ categoryId, modelId, elementsCount: 0 });\n }\n });\n\n return result;\n }),\n mergeAll(),\n ),\n );\n }\n\n public async getCategoryElementsCount(modelId: Id64String, categoryId: Id64String): Promise<number> {\n return this.#categoryElementCounts.getCategoryElementsCount(modelId, categoryId);\n }\n\n public async createCategoryInstanceKeyPaths(categoryId: Id64String): Promise<HierarchyNodeIdentifiersPath[]> {\n let entry = this.#categoryKeyPaths.get(categoryId);\n if (!entry) {\n entry = (async () => {\n const result = new Set<Id64String>();\n const modelInfos = await this.getModelInfos();\n modelInfos?.forEach((modelInfo, modelId) => {\n const categoryEntry = modelInfo.categories.get(categoryId);\n if (categoryEntry?.isRootElementCategory) {\n result.add(modelId);\n }\n });\n\n const categoryPaths = new Array<HierarchyNodeIdentifiersPath>();\n for (const categoryModelId of [...result]) {\n const modelPaths = await this.createModelInstanceKeyPaths(categoryModelId);\n for (const modelPath of modelPaths) {\n categoryPaths.push([...modelPath, { className: \"BisCore.SpatialCategory\", id: categoryId }]);\n }\n }\n return categoryPaths;\n })();\n this.#categoryKeyPaths.set(categoryId, entry);\n }\n return entry;\n }\n}\n\nfunction forEachChildSubject(\n subjectInfos: Map<Id64String, SubjectInfo>,\n parentSubject: Id64String | SubjectInfo,\n cb: (childSubjectId: Id64String, childSubjectInfo: SubjectInfo) => \"break\" | \"continue\",\n) {\n const parentSubjectInfo = typeof parentSubject === \"string\" ? subjectInfos.get(parentSubject) : parentSubject;\n parentSubjectInfo &&\n parentSubjectInfo.childSubjects.forEach((childSubjectId) => {\n const childSubjectInfo = subjectInfos.get(childSubjectId)!;\n if (cb(childSubjectId, childSubjectInfo) === \"break\") {\n return;\n }\n forEachChildSubject(subjectInfos, childSubjectInfo, cb);\n });\n}\n\nclass ModelCategoryElementsCountCache {\n #cache = new Map<string, Subject<number>>();\n #requestsStream = new Subject<{ modelId: Id64String; categoryId: Id64String }>();\n #subscription: Subscription;\n public constructor(\n loader: (\n input: Array<{ modelId: Id64String; categoryId: Id64String }>,\n ) => Promise<Array<{ modelId: Id64String; categoryId: Id64String; elementsCount: number }>>,\n ) {\n this.#subscription = this.#requestsStream\n .pipe(\n bufferTime(20),\n filter((requests) => requests.length > 0),\n mergeMap(async (requests) => loader(requests)),\n mergeAll(),\n )\n .subscribe({\n next: ({ modelId, categoryId, elementsCount }) => {\n const subject = this.#cache.get(`${modelId}${categoryId}`);\n assert(!!subject);\n subject.next(elementsCount);\n },\n });\n }\n\n public [Symbol.dispose]() {\n this.#subscription.unsubscribe();\n }\n\n public async getCategoryElementsCount(modelId: Id64String, categoryId: Id64String): Promise<number> {\n const cacheKey = `${modelId}${categoryId}`;\n let result = this.#cache.get(cacheKey);\n if (result !== undefined) {\n return firstValueFrom(result);\n }\n\n result = new ReplaySubject(1);\n this.#cache.set(cacheKey, result);\n this.#requestsStream.next({ modelId, categoryId });\n return firstValueFrom(result);\n }\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Id64Arg, Id64Array, Id64Set, Id64String } from "@itwin/core-bentley";
|
|
1
|
+
import type { GuidString, Id64Arg, Id64Array, Id64Set, Id64String } from "@itwin/core-bentley";
|
|
2
2
|
import type { Viewport } from "@itwin/core-frontend";
|
|
3
3
|
import type { GroupingHierarchyNode, HierarchyFilteringPath } from "@itwin/presentation-hierarchies";
|
|
4
4
|
import type { ECClassHierarchyInspector } from "@itwin/presentation-shared";
|
|
@@ -70,6 +70,7 @@ export interface ModelsTreeVisibilityHandlerProps {
|
|
|
70
70
|
imodelAccess: ECClassHierarchyInspector;
|
|
71
71
|
overrides?: ModelsTreeVisibilityHandlerOverrides;
|
|
72
72
|
filteredPaths?: HierarchyFilteringPath[];
|
|
73
|
+
componentId?: GuidString;
|
|
73
74
|
}
|
|
74
75
|
/**
|
|
75
76
|
* Creates an instance if `ModelsTreeVisibilityHandler`.
|
|
@@ -79,9 +80,12 @@ export declare function createModelsTreeVisibilityHandler(props: ModelsTreeVisib
|
|
|
79
80
|
/**
|
|
80
81
|
* Enables display of all given models. Also enables display of all categories and clears always and
|
|
81
82
|
* never drawn lists in the viewport.
|
|
83
|
+
*
|
|
84
|
+
* @param componentId Optional unique id of the component that consumes this function.
|
|
85
|
+
* It can be any string, as long as it is not shared across different components.
|
|
82
86
|
* @public
|
|
83
87
|
*/
|
|
84
|
-
export declare function showAllModels(models: string[], viewport: Viewport): Promise<void>;
|
|
88
|
+
export declare function showAllModels(models: string[], viewport: Viewport, componentId?: GuidString): Promise<void>;
|
|
85
89
|
/**
|
|
86
90
|
* Disables display of all given models.
|
|
87
91
|
* @public
|