@itwin/tree-widget-react 3.14.1 → 3.14.2

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.
Files changed (33) hide show
  1. package/CHANGELOG.md +11 -2
  2. package/README.md +3 -0
  3. package/lib/cjs/tree-widget-react/components/trees/categories-tree/CategoriesTreeButtons.js +2 -0
  4. package/lib/cjs/tree-widget-react/components/trees/categories-tree/CategoriesTreeButtons.js.map +1 -1
  5. package/lib/cjs/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTreeDefinition.js +4 -0
  6. package/lib/cjs/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTreeDefinition.js.map +1 -1
  7. package/lib/cjs/tree-widget-react/components/trees/models-tree/ModelsTreeButtons.js +3 -0
  8. package/lib/cjs/tree-widget-react/components/trees/models-tree/ModelsTreeButtons.js.map +1 -1
  9. package/lib/cjs/tree-widget-react/components/trees/models-tree/ModelsTreeDefinition.js +1 -1
  10. package/lib/cjs/tree-widget-react/components/trees/models-tree/ModelsTreeDefinition.js.map +1 -1
  11. package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/AlwaysAndNeverDrawnElementInfo.d.ts +8 -11
  12. package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/AlwaysAndNeverDrawnElementInfo.js +67 -76
  13. package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/AlwaysAndNeverDrawnElementInfo.js.map +1 -1
  14. package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.js +13 -9
  15. package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.js.map +1 -1
  16. package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.js +7 -7
  17. package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.js.map +1 -1
  18. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeButtons.js +2 -0
  19. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeButtons.js.map +1 -1
  20. package/lib/esm/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTreeDefinition.js +4 -0
  21. package/lib/esm/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTreeDefinition.js.map +1 -1
  22. package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeButtons.js +3 -0
  23. package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeButtons.js.map +1 -1
  24. package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeDefinition.js +1 -1
  25. package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeDefinition.js.map +1 -1
  26. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/AlwaysAndNeverDrawnElementInfo.d.ts +8 -11
  27. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/AlwaysAndNeverDrawnElementInfo.js +68 -77
  28. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/AlwaysAndNeverDrawnElementInfo.js.map +1 -1
  29. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.js +13 -9
  30. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.js.map +1 -1
  31. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.js +7 -7
  32. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.js.map +1 -1
  33. package/package.json +1 -1
@@ -2,49 +2,35 @@
2
2
  * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
3
  * See LICENSE.md in the project root for license terms and full copyright notice.
4
4
  *--------------------------------------------------------------------------------------------*/
5
- import { BehaviorSubject, debounceTime, EMPTY, filter, first, from, fromEventPattern, map, merge, reduce, scan, share, shareReplay, startWith, Subject, switchMap, take, takeUntil, tap, } from "rxjs";
5
+ import { BehaviorSubject, debounceTime, defer, EMPTY, filter, first, fromEventPattern, map, mergeMap, of, reduce, scan, share, shareReplay, startWith, Subject, switchMap, take, takeUntil, tap, } from "rxjs";
6
6
  import { Id64 } from "@itwin/core-bentley";
7
7
  import { createECSqlQueryExecutor } from "@itwin/presentation-core-interop";
8
8
  import { pushToMap } from "../../common/Utils.js";
9
+ /** @internal */
9
10
  export const SET_CHANGE_DEBOUNCE_TIME = 20;
10
11
  export class AlwaysAndNeverDrawnElementInfo {
11
- _viewport;
12
- _subscriptions;
13
- _alwaysDrawn;
14
- _neverDrawn;
15
- _disposeSubject = new Subject();
16
- _suppressors;
17
- _suppress = new Subject();
18
- _forceUpdate = new Subject();
19
- constructor(_viewport) {
20
- this._viewport = _viewport;
21
- this._alwaysDrawn = this.createCacheEntryObservable({
22
- event: this._viewport.onAlwaysDrawnChanged,
23
- getSet: () => this._viewport.alwaysDrawn,
24
- id: "alwaysDrawn",
25
- });
26
- this._neverDrawn = this.createCacheEntryObservable({
27
- event: this._viewport.onNeverDrawnChanged,
28
- getSet: () => this._viewport.neverDrawn,
29
- id: "neverDrawn",
30
- });
31
- this._suppressors = this._suppress.pipe(scan((acc, suppress) => acc + (suppress ? 1 : -1), 0), startWith(0), shareReplay(1));
32
- this._subscriptions = [
33
- this._alwaysDrawn.subscribe(),
34
- this._neverDrawn.subscribe(),
35
- this._suppressors.pipe(filter((suppressors) => suppressors === 0)).subscribe({
36
- next: () => this._forceUpdate.next(),
37
- }),
38
- ];
12
+ #subscriptions;
13
+ #alwaysDrawn;
14
+ #neverDrawn;
15
+ #disposeSubject = new Subject();
16
+ #viewport;
17
+ #suppressors;
18
+ #suppress = new Subject();
19
+ constructor(viewport) {
20
+ this.#viewport = viewport;
21
+ this.#alwaysDrawn = { cacheEntryObs: this.createCacheEntryObservable("always") };
22
+ this.#neverDrawn = { cacheEntryObs: this.createCacheEntryObservable("never") };
23
+ this.#suppressors = this.#suppress.pipe(scan((acc, suppress) => acc + (suppress ? 1 : -1), 0), startWith(0), shareReplay(1));
24
+ this.#subscriptions = [this.#alwaysDrawn.cacheEntryObs.subscribe(), this.#neverDrawn.cacheEntryObs.subscribe()];
39
25
  }
40
26
  suppressChangeEvents() {
41
- this._suppress.next(true);
27
+ this.#suppress.next(true);
42
28
  }
43
29
  resumeChangeEvents() {
44
- this._suppress.next(false);
30
+ this.#suppress.next(false);
45
31
  }
46
32
  getElements({ setType, modelId, categoryIds }) {
47
- const cache = setType === "always" ? this._alwaysDrawn : this._neverDrawn;
33
+ const cache = setType === "always" ? this.#alwaysDrawn : this.#neverDrawn;
48
34
  const getElements = categoryIds
49
35
  ? (entry) => {
50
36
  const result = new Set();
@@ -62,26 +48,30 @@ export class AlwaysAndNeverDrawnElementInfo {
62
48
  }
63
49
  return elements;
64
50
  };
65
- return cache.pipe(map(getElements));
51
+ return !cache.latestCacheEntryValue
52
+ ? cache.cacheEntryObs.pipe(map(getElements))
53
+ : this.#suppressors.pipe(take(1), mergeMap((suppressionCount) => suppressionCount > 0 ? of(cache.latestCacheEntryValue).pipe(map(getElements)) : cache.cacheEntryObs.pipe(map(getElements))));
66
54
  }
67
- createCacheEntryObservable(props) {
68
- const event = props.event;
55
+ createCacheEntryObservable(setType) {
56
+ const event = setType === "always" ? this.#viewport.onAlwaysDrawnChanged : this.#viewport.onNeverDrawnChanged;
57
+ const getIds = setType === "always" ? () => this.#viewport.alwaysDrawn : () => this.#viewport.neverDrawn;
69
58
  const resultSubject = new BehaviorSubject(undefined);
70
- const obs = merge(fromEventPattern((handler) => event.addListener(handler), (handler) => event.removeListener(handler)), this._forceUpdate).pipe(
59
+ const obs = fromEventPattern((handler) => event.addListener(handler), (handler) => event.removeListener(handler)).pipe(
71
60
  // Fire the observable once at the beginning
72
61
  startWith(undefined),
73
- // Stop listening to events when dispose() is called
74
- takeUntil(this._disposeSubject),
75
62
  // Reset result subject as soon as a new event is emitted.
76
63
  // This will make newly subscribed observers wait for the debounce period to pass
77
64
  // instead of consuming the cached value which at this point becomes invalid.
78
65
  tap(() => resultSubject.next(undefined)),
79
66
  // Check if cache updates are not suppressed.
80
- switchMap(() => this._suppressors.pipe(filter((suppressors) => suppressors === 0), take(1))), debounceTime(SET_CHANGE_DEBOUNCE_TIME),
67
+ switchMap(() => this.#suppressors.pipe(filter((suppressors) => suppressors === 0), take(1))), debounceTime(SET_CHANGE_DEBOUNCE_TIME),
81
68
  // Cancel pending request if dispose() is called.
82
- takeUntil(this._disposeSubject),
69
+ takeUntil(this.#disposeSubject),
83
70
  // If multiple requests are sent at once, preserve only the result of the newest.
84
- switchMap(() => this.queryAlwaysOrNeverDrawnElementInfo(props.getSet(), props.id)),
71
+ switchMap(() => this.queryAlwaysOrNeverDrawnElementInfo(getIds(), `${setType}Drawn`)), tap((cacheEntry) => {
72
+ const value = setType === "always" ? this.#alwaysDrawn : this.#neverDrawn;
73
+ value.latestCacheEntryValue = cacheEntry;
74
+ }),
85
75
  // Share the result by using a subject which always emits the saved result.
86
76
  share({
87
77
  connector: () => resultSubject,
@@ -92,9 +82,9 @@ export class AlwaysAndNeverDrawnElementInfo {
92
82
  return obs;
93
83
  }
94
84
  [Symbol.dispose]() {
95
- this._subscriptions.forEach((x) => x.unsubscribe());
96
- this._subscriptions = [];
97
- this._disposeSubject.next();
85
+ this.#subscriptions.forEach((x) => x.unsubscribe());
86
+ this.#subscriptions = [];
87
+ this.#disposeSubject.next();
98
88
  }
99
89
  queryAlwaysOrNeverDrawnElementInfo(set, requestId) {
100
90
  const elementInfo = set?.size ? this.queryElementInfo([...set], requestId) : EMPTY;
@@ -109,41 +99,42 @@ export class AlwaysAndNeverDrawnElementInfo {
109
99
  }, new Map()));
110
100
  }
111
101
  queryElementInfo(elementIds, requestId) {
112
- const executor = createECSqlQueryExecutor(this._viewport.iModel);
113
- const reader = executor.createQueryReader({
114
- ctes: [
115
- `
116
- ElementInfo(elementId, modelId, categoryId, parentId) AS (
117
- SELECT
118
- ECInstanceId elementId,
119
- Model.Id modelId,
120
- Category.Id categoryId,
121
- Parent.Id parentId
122
- FROM bis.GeometricElement3d
123
- WHERE InVirtualSet(?, ECInstanceId)
102
+ return defer(() => {
103
+ const executor = createECSqlQueryExecutor(this.#viewport.iModel);
104
+ return executor.createQueryReader({
105
+ ctes: [
106
+ `
107
+ ElementInfo(elementId, modelId, categoryId, parentId) AS (
108
+ SELECT
109
+ ECInstanceId elementId,
110
+ Model.Id modelId,
111
+ Category.Id categoryId,
112
+ Parent.Id parentId
113
+ FROM bis.GeometricElement3d
114
+ WHERE InVirtualSet(?, ECInstanceId)
124
115
 
125
- UNION ALL
116
+ UNION ALL
126
117
 
127
- SELECT
128
- e.elementId,
129
- e.modelId,
130
- p.Category.Id categoryId,
131
- p.Parent.Id parentId
132
- FROM bis.GeometricElement3d p
133
- JOIN ElementInfo e ON p.ECInstanceId = e.parentId
134
- )
135
- `,
136
- ],
137
- ecsql: `
138
- SELECT elementId, modelId, categoryId
139
- FROM ElementInfo
140
- WHERE parentId IS NULL
141
- `,
142
- bindings: [{ type: "idset", value: elementIds }],
143
- }, {
144
- restartToken: `ModelsTreeVisibilityHandler/${requestId}`,
145
- });
146
- return from(reader).pipe(map((row) => ({ elementId: row.elementId, modelId: row.modelId, categoryId: row.categoryId })));
118
+ SELECT
119
+ e.elementId,
120
+ e.modelId,
121
+ p.Category.Id categoryId,
122
+ p.Parent.Id parentId
123
+ FROM bis.GeometricElement3d p
124
+ JOIN ElementInfo e ON p.ECInstanceId = e.parentId
125
+ )
126
+ `,
127
+ ],
128
+ ecsql: `
129
+ SELECT elementId, modelId, categoryId
130
+ FROM ElementInfo
131
+ WHERE parentId IS NULL
132
+ `,
133
+ bindings: [{ type: "idset", value: elementIds }],
134
+ }, {
135
+ restartToken: `ModelsTreeVisibilityHandler/${requestId}`,
136
+ });
137
+ }).pipe(map((row) => ({ elementId: row.elementId, modelId: row.modelId, categoryId: row.categoryId })));
147
138
  }
148
139
  }
149
140
  //# sourceMappingURL=AlwaysAndNeverDrawnElementInfo.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"AlwaysAndNeverDrawnElementInfo.js","sourceRoot":"","sources":["../../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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 {\n BehaviorSubject,\n debounceTime,\n EMPTY,\n filter,\n first,\n from,\n fromEventPattern,\n map,\n merge,\n reduce,\n scan,\n share,\n shareReplay,\n startWith,\n Subject,\n switchMap,\n take,\n takeUntil,\n tap,\n} from \"rxjs\";\nimport { Id64 } from \"@itwin/core-bentley\";\nimport { createECSqlQueryExecutor } from \"@itwin/presentation-core-interop\";\nimport { pushToMap } from \"../../common/Utils.js\";\n\nimport type { BeEvent, Id64Arg, Id64Array, Id64Set, Id64String } from \"@itwin/core-bentley\";\nimport type { Observable, Subscription } from \"rxjs\";\nimport type { Viewport } from \"@itwin/core-frontend\";\n\ninterface ElementInfo {\n elementId: Id64String;\n modelId: Id64String;\n categoryId: Id64String;\n}\n\ntype CacheEntry = Map<Id64String, Map<Id64String, Id64Set>>;\n\nexport interface AlwaysOrNeverDrawnElementsQueryProps {\n modelId: Id64String;\n categoryIds?: Id64Arg;\n}\n\nexport const SET_CHANGE_DEBOUNCE_TIME = 20;\n\nexport class AlwaysAndNeverDrawnElementInfo implements Disposable {\n private _subscriptions: Subscription[];\n private _alwaysDrawn: Observable<CacheEntry>;\n private _neverDrawn: Observable<CacheEntry>;\n private _disposeSubject = new Subject<void>();\n\n private _suppressors: Observable<number>;\n private _suppress = new Subject<boolean>();\n private _forceUpdate = new Subject<void>();\n\n constructor(private readonly _viewport: Viewport) {\n this._alwaysDrawn = this.createCacheEntryObservable({\n event: this._viewport.onAlwaysDrawnChanged,\n getSet: () => this._viewport.alwaysDrawn,\n id: \"alwaysDrawn\",\n });\n this._neverDrawn = this.createCacheEntryObservable({\n event: this._viewport.onNeverDrawnChanged,\n getSet: () => this._viewport.neverDrawn,\n id: \"neverDrawn\",\n });\n this._suppressors = this._suppress.pipe(\n scan((acc, suppress) => acc + (suppress ? 1 : -1), 0),\n startWith(0),\n shareReplay(1),\n );\n this._subscriptions = [\n this._alwaysDrawn.subscribe(),\n this._neverDrawn.subscribe(),\n this._suppressors.pipe(filter((suppressors) => suppressors === 0)).subscribe({\n next: () => this._forceUpdate.next(),\n }),\n ];\n }\n\n public suppressChangeEvents() {\n this._suppress.next(true);\n }\n\n public resumeChangeEvents() {\n this._suppress.next(false);\n }\n\n public getElements({ setType, modelId, categoryIds }: { setType: \"always\" | \"never\" } & AlwaysOrNeverDrawnElementsQueryProps): Observable<Id64Set> {\n const cache = setType === \"always\" ? this._alwaysDrawn : this._neverDrawn;\n const getElements = categoryIds\n ? (entry: CacheEntry | undefined) => {\n const result = new Set<Id64String>();\n for (const categoryId of Id64.iterable(categoryIds)) {\n const elements = entry?.get(modelId)?.get(categoryId);\n elements?.forEach((elementId) => result.add(elementId));\n }\n return result;\n }\n : (entry: CacheEntry | undefined) => {\n const modelEntry = entry?.get(modelId);\n const elements = new Set<Id64String>();\n for (const set of modelEntry?.values() ?? []) {\n set.forEach((id) => elements.add(id));\n }\n return elements;\n };\n\n return cache.pipe(map(getElements));\n }\n\n private createCacheEntryObservable(props: { event: BeEvent<() => void>; getSet(): Id64Set | undefined; id: string }) {\n const event = props.event;\n const resultSubject = new BehaviorSubject<CacheEntry | undefined>(undefined);\n\n const obs = merge(\n fromEventPattern(\n (handler) => event.addListener(handler),\n (handler) => event.removeListener(handler),\n ),\n this._forceUpdate,\n ).pipe(\n // Fire the observable once at the beginning\n startWith(undefined),\n // Stop listening to events when dispose() is called\n takeUntil(this._disposeSubject),\n // Reset result subject as soon as a new event is emitted.\n // This will make newly subscribed observers wait for the debounce period to pass\n // instead of consuming the cached value which at this point becomes invalid.\n tap(() => resultSubject.next(undefined)),\n // Check if cache updates are not suppressed.\n switchMap(() =>\n this._suppressors.pipe(\n filter((suppressors) => suppressors === 0),\n take(1),\n ),\n ),\n debounceTime(SET_CHANGE_DEBOUNCE_TIME),\n // Cancel pending request if dispose() is called.\n takeUntil(this._disposeSubject),\n // If multiple requests are sent at once, preserve only the result of the newest.\n switchMap(() => this.queryAlwaysOrNeverDrawnElementInfo(props.getSet(), props.id)),\n // Share the result by using a subject which always emits the saved result.\n share({\n connector: () => resultSubject,\n resetOnRefCountZero: false,\n }),\n // Wait until the result is available.\n first((x): x is CacheEntry => !!x),\n );\n return obs;\n }\n\n public [Symbol.dispose]() {\n this._subscriptions.forEach((x) => x.unsubscribe());\n this._subscriptions = [];\n this._disposeSubject.next();\n }\n\n private queryAlwaysOrNeverDrawnElementInfo(set: Id64Set | undefined, requestId: string): Observable<CacheEntry> {\n const elementInfo = set?.size ? this.queryElementInfo([...set], requestId) : EMPTY;\n return elementInfo.pipe(\n reduce((state, val) => {\n let entry = state.get(val.modelId);\n if (!entry) {\n entry = new Map();\n state.set(val.modelId, entry);\n }\n pushToMap(entry, val.categoryId, val.elementId);\n return state;\n }, new Map<Id64String, Map<Id64String, Id64Set>>()),\n );\n }\n\n private queryElementInfo(elementIds: Id64Array, requestId: string): Observable<ElementInfo> {\n const executor = createECSqlQueryExecutor(this._viewport.iModel);\n const reader = executor.createQueryReader(\n {\n ctes: [\n `\n ElementInfo(elementId, modelId, categoryId, parentId) AS (\n SELECT\n ECInstanceId elementId,\n Model.Id modelId,\n Category.Id categoryId,\n Parent.Id parentId\n FROM bis.GeometricElement3d\n WHERE InVirtualSet(?, ECInstanceId)\n\n UNION ALL\n\n SELECT\n e.elementId,\n e.modelId,\n p.Category.Id categoryId,\n p.Parent.Id parentId\n FROM bis.GeometricElement3d p\n JOIN ElementInfo e ON p.ECInstanceId = e.parentId\n )\n `,\n ],\n ecsql: `\n SELECT elementId, modelId, categoryId\n FROM ElementInfo\n WHERE parentId IS NULL\n `,\n bindings: [{ type: \"idset\", value: elementIds }],\n },\n {\n restartToken: `ModelsTreeVisibilityHandler/${requestId}`,\n },\n );\n\n return from(reader).pipe(map((row) => ({ elementId: row.elementId, modelId: row.modelId, categoryId: row.categoryId })));\n }\n}\n"]}
1
+ {"version":3,"file":"AlwaysAndNeverDrawnElementInfo.js","sourceRoot":"","sources":["../../../../../../../src/tree-widget-react/components/trees/models-tree/internal/AlwaysAndNeverDrawnElementInfo.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EACL,eAAe,EACf,YAAY,EACZ,KAAK,EACL,KAAK,EACL,MAAM,EACN,KAAK,EACL,gBAAgB,EAChB,GAAG,EACH,QAAQ,EACR,EAAE,EACF,MAAM,EACN,IAAI,EACJ,KAAK,EACL,WAAW,EACX,SAAS,EACT,OAAO,EACP,SAAS,EACT,IAAI,EACJ,SAAS,EACT,GAAG,GACJ,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAC3C,OAAO,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAMlD,gBAAgB;AAChB,MAAM,CAAC,MAAM,wBAAwB,GAAG,EAAE,CAAC;AAY3C,MAAM,OAAO,8BAA8B;IACzC,cAAc,CAAiB;IAC/B,YAAY,CAAgF;IAC5F,WAAW,CAAgF;IAC3F,eAAe,GAAG,IAAI,OAAO,EAAQ,CAAC;IAC7B,SAAS,CAAW;IAE7B,YAAY,CAAqB;IACjC,SAAS,GAAG,IAAI,OAAO,EAAW,CAAC;IAEnC,YAAY,QAAkB;QAC5B,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;QAC1B,IAAI,CAAC,YAAY,GAAG,EAAE,aAAa,EAAE,IAAI,CAAC,0BAA0B,CAAC,QAAQ,CAAC,EAAE,CAAC;QACjF,IAAI,CAAC,WAAW,GAAG,EAAE,aAAa,EAAE,IAAI,CAAC,0BAA0B,CAAC,OAAO,CAAC,EAAE,CAAC;QAC/E,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CACrC,IAAI,CAAC,CAAC,GAAG,EAAE,QAAQ,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC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;gBACD,KAAK,EAAE;;;;WAIN;gBACD,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC;aACjD,EACD;gBACE,YAAY,EAAE,+BAA+B,SAAS,EAAE;aACzD,CACF,CAAC;QACJ,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,EAAE,SAAS,EAAE,GAAG,CAAC,SAAS,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,UAAU,EAAE,GAAG,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,CAAC;IAC1G,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 {\n BehaviorSubject,\n debounceTime,\n defer,\n EMPTY,\n filter,\n first,\n fromEventPattern,\n map,\n mergeMap,\n of,\n reduce,\n scan,\n share,\n shareReplay,\n startWith,\n Subject,\n switchMap,\n take,\n takeUntil,\n tap,\n} from \"rxjs\";\nimport { Id64 } from \"@itwin/core-bentley\";\nimport { createECSqlQueryExecutor } from \"@itwin/presentation-core-interop\";\nimport { pushToMap } from \"../../common/Utils.js\";\n\nimport type { Id64Arg, Id64Array, Id64Set, Id64String } from \"@itwin/core-bentley\";\nimport type { Observable, Subscription } from \"rxjs\";\nimport type { Viewport } from \"@itwin/core-frontend\";\n\n/** @internal */\nexport const SET_CHANGE_DEBOUNCE_TIME = 20;\n\ntype SetType = \"always\" | \"never\";\n\n/** @internal */\nexport interface AlwaysOrNeverDrawnElementsQueryProps {\n modelId: Id64String;\n categoryIds?: Id64Arg;\n}\n\ntype CacheEntry = Map<Id64String, Map<Id64String, Id64Set>>;\n\nexport class AlwaysAndNeverDrawnElementInfo implements Disposable {\n #subscriptions: Subscription[];\n #alwaysDrawn: { cacheEntryObs: Observable<CacheEntry>; latestCacheEntryValue?: CacheEntry };\n #neverDrawn: { cacheEntryObs: Observable<CacheEntry>; latestCacheEntryValue?: CacheEntry };\n #disposeSubject = new Subject<void>();\n readonly #viewport: Viewport;\n\n #suppressors: Observable<number>;\n #suppress = new Subject<boolean>();\n\n constructor(viewport: Viewport) {\n this.#viewport = viewport;\n this.#alwaysDrawn = { cacheEntryObs: this.createCacheEntryObservable(\"always\") };\n this.#neverDrawn = { cacheEntryObs: this.createCacheEntryObservable(\"never\") };\n this.#suppressors = this.#suppress.pipe(\n scan((acc, suppress) => acc + (suppress ? 1 : -1), 0),\n startWith(0),\n shareReplay(1),\n );\n this.#subscriptions = [this.#alwaysDrawn.cacheEntryObs.subscribe(), this.#neverDrawn.cacheEntryObs.subscribe()];\n }\n\n public suppressChangeEvents() {\n this.#suppress.next(true);\n }\n\n public resumeChangeEvents() {\n this.#suppress.next(false);\n }\n\n public getElements({ setType, modelId, categoryIds }: { setType: SetType } & AlwaysOrNeverDrawnElementsQueryProps): Observable<Id64Set> {\n const cache = setType === \"always\" ? this.#alwaysDrawn : this.#neverDrawn;\n const getElements = categoryIds\n ? (entry: CacheEntry | undefined) => {\n const result = new Set<Id64String>();\n for (const categoryId of Id64.iterable(categoryIds)) {\n const elements = entry?.get(modelId)?.get(categoryId);\n elements?.forEach((elementId) => result.add(elementId));\n }\n return result;\n }\n : (entry: CacheEntry | undefined) => {\n const modelEntry = entry?.get(modelId);\n const elements = new Set<Id64String>();\n for (const set of modelEntry?.values() ?? []) {\n set.forEach((id) => elements.add(id));\n }\n return elements;\n };\n\n return !cache.latestCacheEntryValue\n ? cache.cacheEntryObs.pipe(map(getElements))\n : this.#suppressors.pipe(\n take(1),\n mergeMap((suppressionCount) =>\n suppressionCount > 0 ? of(cache.latestCacheEntryValue).pipe(map(getElements)) : cache.cacheEntryObs.pipe(map(getElements)),\n ),\n );\n }\n\n private createCacheEntryObservable(setType: SetType): Observable<CacheEntry> {\n const event = setType === \"always\" ? this.#viewport.onAlwaysDrawnChanged : this.#viewport.onNeverDrawnChanged;\n const getIds = setType === \"always\" ? () => this.#viewport.alwaysDrawn : () => this.#viewport.neverDrawn;\n\n const resultSubject = new BehaviorSubject<CacheEntry | undefined>(undefined);\n\n const obs = fromEventPattern(\n (handler) => event.addListener(handler),\n (handler) => event.removeListener(handler),\n ).pipe(\n // Fire the observable once at the beginning\n startWith(undefined),\n // Reset result subject as soon as a new event is emitted.\n // This will make newly subscribed observers wait for the debounce period to pass\n // instead of consuming the cached value which at this point becomes invalid.\n tap(() => resultSubject.next(undefined)),\n // Check if cache updates are not suppressed.\n switchMap(() =>\n this.#suppressors.pipe(\n filter((suppressors) => suppressors === 0),\n take(1),\n ),\n ),\n debounceTime(SET_CHANGE_DEBOUNCE_TIME),\n // Cancel pending request if dispose() is called.\n takeUntil(this.#disposeSubject),\n // If multiple requests are sent at once, preserve only the result of the newest.\n switchMap(() => this.queryAlwaysOrNeverDrawnElementInfo(getIds(), `${setType}Drawn`)),\n tap((cacheEntry) => {\n const value = setType === \"always\" ? this.#alwaysDrawn : this.#neverDrawn;\n value.latestCacheEntryValue = cacheEntry;\n }),\n // Share the result by using a subject which always emits the saved result.\n share({\n connector: () => resultSubject,\n resetOnRefCountZero: false,\n }),\n // Wait until the result is available.\n first((x): x is CacheEntry => !!x),\n );\n return obs;\n }\n\n public [Symbol.dispose]() {\n this.#subscriptions.forEach((x) => x.unsubscribe());\n this.#subscriptions = [];\n this.#disposeSubject.next();\n }\n\n private queryAlwaysOrNeverDrawnElementInfo(set: Id64Set | undefined, requestId: string): Observable<CacheEntry> {\n const elementInfo = set?.size ? this.queryElementInfo([...set], requestId) : EMPTY;\n return elementInfo.pipe(\n reduce((state, val) => {\n let entry = state.get(val.modelId);\n if (!entry) {\n entry = new Map();\n state.set(val.modelId, entry);\n }\n pushToMap(entry, val.categoryId, val.elementId);\n return state;\n }, new Map<Id64String, Map<Id64String, Id64Set>>()),\n );\n }\n\n private queryElementInfo(\n elementIds: Id64Array,\n requestId: string,\n ): Observable<{\n elementId: Id64String;\n modelId: Id64String;\n categoryId: Id64String;\n }> {\n return defer(() => {\n const executor = createECSqlQueryExecutor(this.#viewport.iModel);\n return executor.createQueryReader(\n {\n ctes: [\n `\n ElementInfo(elementId, modelId, categoryId, parentId) AS (\n SELECT\n ECInstanceId elementId,\n Model.Id modelId,\n Category.Id categoryId,\n Parent.Id parentId\n FROM bis.GeometricElement3d\n WHERE InVirtualSet(?, ECInstanceId)\n\n UNION ALL\n\n SELECT\n e.elementId,\n e.modelId,\n p.Category.Id categoryId,\n p.Parent.Id parentId\n FROM bis.GeometricElement3d p\n JOIN ElementInfo e ON p.ECInstanceId = e.parentId\n )\n `,\n ],\n ecsql: `\n SELECT elementId, modelId, categoryId\n FROM ElementInfo\n WHERE parentId IS NULL\n `,\n bindings: [{ type: \"idset\", value: elementIds }],\n },\n {\n restartToken: `ModelsTreeVisibilityHandler/${requestId}`,\n },\n );\n }).pipe(map((row) => ({ elementId: row.elementId, modelId: row.modelId, categoryId: row.categoryId })));\n }\n}\n"]}
@@ -213,15 +213,18 @@ export class ModelsTreeIdsCache {
213
213
  return entry;
214
214
  }
215
215
  async *queryModelCategories() {
216
- const query = /* sql */ `
217
- SELECT this.Model.Id modelId, this.Category.Id categoryId, m.IsPrivate isModelPrivate
216
+ const query = `
217
+ SELECT
218
+ this.Model.Id modelId,
219
+ this.Category.Id categoryId,
220
+ m.IsPrivate isModelPrivate,
221
+ MAX(IIF(this.Parent.Id IS NULL, 1, 0)) isRootElementCategory
218
222
  FROM BisCore.Model m
219
223
  JOIN ${this._hierarchyConfig.elementClassSpecification} this ON m.ECInstanceId = this.Model.Id
220
- WHERE this.Parent.Id IS NULL
221
224
  GROUP BY modelId, categoryId, isModelPrivate
222
225
  `;
223
226
  for await (const row of this._queryExecutor.createQueryReader({ ecsql: query }, { rowFormat: "ECSqlPropertyNames", limit: "unbounded" })) {
224
- yield { modelId: row.modelId, categoryId: row.categoryId, isModelPrivate: !!row.isModelPrivate };
227
+ yield { modelId: row.modelId, categoryId: row.categoryId, isModelPrivate: !!row.isModelPrivate, isRootElementCategory: !!row.isRootElementCategory };
225
228
  }
226
229
  }
227
230
  async *queryModeledElements() {
@@ -260,14 +263,14 @@ export class ModelsTreeIdsCache {
260
263
  async getModelInfos() {
261
264
  this._modelInfos ??= (async () => {
262
265
  const modelInfos = new Map();
263
- for await (const { modelId, categoryId, isModelPrivate } of this.queryModelCategories()) {
266
+ for await (const { modelId, categoryId, isModelPrivate, isRootElementCategory } of this.queryModelCategories()) {
264
267
  const entry = modelInfos.get(modelId);
265
268
  if (entry) {
266
- entry.categories.add(categoryId);
269
+ entry.categories.set(categoryId, { isRootElementCategory });
267
270
  entry.isModelPrivate = isModelPrivate;
268
271
  }
269
272
  else {
270
- modelInfos.set(modelId, { categories: new Set([categoryId]), isModelPrivate });
273
+ modelInfos.set(modelId, { categories: new Map([[categoryId, { isRootElementCategory }]]), isModelPrivate });
271
274
  }
272
275
  }
273
276
  return modelInfos;
@@ -276,7 +279,7 @@ export class ModelsTreeIdsCache {
276
279
  }
277
280
  async getModelCategories(modelId) {
278
281
  const modelInfos = await this.getModelInfos();
279
- const categories = modelInfos.get(modelId)?.categories;
282
+ const categories = modelInfos.get(modelId)?.categories.keys();
280
283
  return categories ? [...categories] : [];
281
284
  }
282
285
  async hasSubModel(elementId) {
@@ -373,7 +376,8 @@ export class ModelsTreeIdsCache {
373
376
  const result = new Set();
374
377
  const modelInfos = await this.getModelInfos();
375
378
  modelInfos?.forEach((modelInfo, modelId) => {
376
- if (modelInfo.categories.has(categoryId)) {
379
+ const categoryEntry = modelInfo.categories.get(categoryId);
380
+ if (categoryEntry?.isRootElementCategory) {
377
381
  result.add(modelId);
378
382
  }
379
383
  });
@@ -1 +1 @@
1
- {"version":3,"file":"ModelsTreeIdsCache.js","sourceRoot":"","sources":["../../../../../../../src/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.ts"],"names":[],"mappings":"AAAA;;;gGAG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AC,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 type { Subscription } from \"rxjs\";\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 { 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: Id64Set;\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() {\n const query = /* sql */ `\n SELECT this.Model.Id modelId, this.Category.Id categoryId, m.IsPrivate isModelPrivate\n FROM BisCore.Model m\n JOIN ${this._hierarchyConfig.elementClassSpecification} this ON m.ECInstanceId = this.Model.Id\n WHERE this.Parent.Id IS NULL\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 };\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: Id64Set; isModelPrivate: boolean }>();\n for await (const { modelId, categoryId, isModelPrivate } of this.queryModelCategories()) {\n const entry = modelInfos.get(modelId);\n if (entry) {\n entry.categories.add(categoryId);\n entry.isModelPrivate = isModelPrivate;\n } else {\n modelInfos.set(modelId, { categories: new Set([categoryId]), 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;\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: number; categoryId: number; 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: number; categoryId: number; elementsCount: number }>();\n for await (const row of reader) {\n result.push({ modelId: row.modelId, categoryId: row.categoryId, elementsCount: row.elementsCount });\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 if (modelInfo.categories.has(categoryId)) {\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: number; categoryId: number; 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,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,s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C;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: number; categoryId: number; 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: number; categoryId: number; elementsCount: number }>();\n for await (const row of reader) {\n result.push({ modelId: row.modelId, categoryId: row.categoryId, elementsCount: row.elementsCount });\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: number; categoryId: number; 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"]}
@@ -307,13 +307,13 @@ class ModelsTreeVisibilityHandlerImpl {
307
307
  }
308
308
  return undefined;
309
309
  }
310
- getElementVisibility(ignoreTooltip, viewsModel, overridenVisibility, categoryVisibility, subModelVisibilityStatus) {
310
+ getElementVisibility(ignoreTooltip, viewsModel, overriddenVisibility, categoryVisibility, subModelVisibilityStatus) {
311
311
  if (subModelVisibilityStatus === undefined) {
312
312
  if (!viewsModel) {
313
313
  return createVisibilityStatus("hidden", getTooltipOptions("modelsTree.element.hiddenThroughModel", ignoreTooltip));
314
314
  }
315
- if (overridenVisibility) {
316
- return overridenVisibility;
315
+ if (overriddenVisibility) {
316
+ return overriddenVisibility;
317
317
  }
318
318
  return createVisibilityStatus(categoryVisibility.state, getTooltipOptions(categoryVisibility.state === "visible" ? undefined : "modelsTree.element.hiddenThroughCategory", ignoreTooltip));
319
319
  }
@@ -321,7 +321,7 @@ class ModelsTreeVisibilityHandlerImpl {
321
321
  return createVisibilityStatus("partial", getTooltipOptions("modelsTree.element.someElementsAreHidden", ignoreTooltip));
322
322
  }
323
323
  if (subModelVisibilityStatus.state === "visible") {
324
- if (!viewsModel || overridenVisibility?.state === "hidden" || (categoryVisibility.state === "hidden" && !overridenVisibility)) {
324
+ if (!viewsModel || overriddenVisibility?.state === "hidden" || (categoryVisibility.state === "hidden" && !overriddenVisibility)) {
325
325
  return createVisibilityStatus("partial", getTooltipOptions("modelsTree.element.partialThroughSubModel", ignoreTooltip));
326
326
  }
327
327
  return createVisibilityStatus("visible", getTooltipOptions(undefined, ignoreTooltip));
@@ -329,9 +329,9 @@ class ModelsTreeVisibilityHandlerImpl {
329
329
  if (!viewsModel) {
330
330
  return createVisibilityStatus("hidden", getTooltipOptions("modelsTree.element.hiddenThroughModel", ignoreTooltip));
331
331
  }
332
- if (overridenVisibility) {
333
- if (overridenVisibility.state === "hidden") {
334
- return overridenVisibility;
332
+ if (overriddenVisibility) {
333
+ if (overriddenVisibility.state === "hidden") {
334
+ return overriddenVisibility;
335
335
  }
336
336
  return createVisibilityStatus("partial", getTooltipOptions("modelsTree.element.partialThroughElement", ignoreTooltip));
337
337
  }