@itwin/core-backend 5.12.0-dev.15 → 5.12.0-dev.16

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.
@@ -2,11 +2,67 @@
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
+ var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
6
+ if (value !== null && value !== void 0) {
7
+ if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
8
+ var dispose, inner;
9
+ if (async) {
10
+ if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
11
+ dispose = value[Symbol.asyncDispose];
12
+ }
13
+ if (dispose === void 0) {
14
+ if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
15
+ dispose = value[Symbol.dispose];
16
+ if (async) inner = dispose;
17
+ }
18
+ if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
19
+ if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
20
+ env.stack.push({ value: value, dispose: dispose, async: async });
21
+ }
22
+ else if (async) {
23
+ env.stack.push({ async: true });
24
+ }
25
+ return value;
26
+ };
27
+ var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
28
+ return function (env) {
29
+ function fail(e) {
30
+ env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
31
+ env.hasError = true;
32
+ }
33
+ var r, s = 0;
34
+ function next() {
35
+ while (r = env.stack.pop()) {
36
+ try {
37
+ if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
38
+ if (r.dispose) {
39
+ var result = r.dispose.call(r.value);
40
+ if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
41
+ }
42
+ else s |= 1;
43
+ }
44
+ catch (e) {
45
+ fail(e);
46
+ }
47
+ }
48
+ if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
49
+ if (env.hasError) throw env.error;
50
+ }
51
+ return next();
52
+ };
53
+ })(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
54
+ var e = new Error(message);
55
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
56
+ });
5
57
  import { assert, expect } from "chai";
6
- import { QueryOptionsBuilder, QueryRowFormat } from "@itwin/core-common";
58
+ import * as sinon from "sinon";
59
+ import { QueryBinder, QueryOptionsBuilder, QueryRowFormat } from "@itwin/core-common";
7
60
  import { SnapshotDb } from "../../IModelDb";
8
61
  import { IModelTestUtils } from "../IModelTestUtils";
9
62
  import { Id64 } from "@itwin/core-bentley";
63
+ import { ECSqlStatement } from "../../ECSqlStatement";
64
+ import { ECDbTestHelper } from "./ECDbTestHelper";
65
+ import { KnownTestLocations } from "../KnownTestLocations";
10
66
  describe("WithQueryReaderTests", () => {
11
67
  let iModel;
12
68
  before(async () => {
@@ -119,5 +175,87 @@ describe("WithQueryReaderTests", () => {
119
175
  assert.equal(classId, "BisCore.DrawingCategory");
120
176
  }, undefined, config);
121
177
  });
178
+ describe("statement caching (regression)", () => {
179
+ // `withQueryReader` used to build a fresh `ECSqlStatement` and re-compile the ECSQL on every
180
+ // call (via `ECSqlRowExecutor`), with no caching. Callers such as `IModelTransformer` invoke
181
+ // per-element helpers (e.g. `hasSubModel`) once per element, so on large models this turned one
182
+ // cached ECSQL prepare into N full native compiles - a significant performance regression. The
183
+ // reader now reuses a prepared statement from the owning db's `_statementCache`.
184
+ const sql = "SELECT ECInstanceId FROM bis.Element WHERE ECInstanceId=?";
185
+ afterEach(() => sinon.restore());
186
+ it("reuses a single prepared statement across repeated calls instead of re-preparing", () => {
187
+ iModel.clearCaches();
188
+ const prepareSpy = sinon.spy(ECSqlStatement.prototype, "prepare"); // eslint-disable-line @typescript-eslint/no-deprecated
189
+ for (let i = 0; i < 20; i++) {
190
+ iModel.withQueryReader(sql, (reader) => {
191
+ reader.step();
192
+ }, new QueryBinder().bindId(1, "0x1"));
193
+ }
194
+ expect(prepareSpy.callCount).to.equal(1, "queries with identical ECSQL text should re-use one cached prepared statement");
195
+ });
196
+ it("keeps nested withQueryReader calls on the same SQL independent", () => {
197
+ iModel.clearCaches();
198
+ // A nested reader on the same SQL must get its own statement (findAndRemove hands the outer
199
+ // reader's statement out of the cache), so results do not corrupt each other.
200
+ const outerId = iModel.withQueryReader(sql, (outer) => {
201
+ assert.isTrue(outer.step());
202
+ const innerId = iModel.withQueryReader(sql, (inner) => {
203
+ assert.isTrue(inner.step());
204
+ return inner.current[0];
205
+ }, new QueryBinder().bindId(1, "0xe"));
206
+ expect(innerId).to.equal("0xe");
207
+ // Outer reader's cursor must be unaffected by the nested reader.
208
+ return outer.current[0];
209
+ }, new QueryBinder().bindId(1, "0x1"));
210
+ expect(outerId).to.equal("0x1");
211
+ });
212
+ it("recovers from a prepare failure without poisoning the cache", () => {
213
+ iModel.clearCaches();
214
+ const invalidSql = "SELECT * FROM bis.ThisClassDoesNotExist";
215
+ const prepareSpy = sinon.spy(ECSqlStatement.prototype, "prepare"); // eslint-disable-line @typescript-eslint/no-deprecated
216
+ expect(() => iModel.withQueryReader(invalidSql, (reader) => reader.step())).to.throw();
217
+ expect(() => iModel.withQueryReader(invalidSql, (reader) => reader.step())).to.throw();
218
+ expect(prepareSpy.callCount).to.equal(2, "a statement that failed to prepare must not be cached");
219
+ iModel.withQueryReader(sql, (reader) => {
220
+ assert.isTrue(reader.step());
221
+ expect(reader.current[0]).to.equal("0x1");
222
+ }, new QueryBinder().bindId(1, "0x1"));
223
+ });
224
+ it("releases the executor and cached statement when binding fails during reader construction", () => {
225
+ iModel.clearCaches();
226
+ const prepareSpy = sinon.spy(ECSqlStatement.prototype, "prepare"); // eslint-disable-line @typescript-eslint/no-deprecated
227
+ iModel.withQueryReader(sql, (reader) => reader.step(), new QueryBinder().bindId(1, "0x1"));
228
+ const listenerCount = iModel.onBeforeClose.numberOfListeners;
229
+ const bindStub = sinon.stub(ECSqlStatement.prototype, "bindParams").throws(new Error("Expected bind failure")); // eslint-disable-line @typescript-eslint/no-deprecated
230
+ expect(() => iModel.withQueryReader(sql, () => undefined, new QueryBinder().bindId(1, "0x1"))).to.throw("Expected bind failure");
231
+ bindStub.restore();
232
+ expect(iModel.onBeforeClose.numberOfListeners).to.equal(listenerCount);
233
+ iModel.withQueryReader(sql, (reader) => reader.step(), new QueryBinder().bindId(1, "0x1"));
234
+ expect(prepareSpy.callCount).to.equal(1, "the statement checked out before the bind failure should be returned to the cache");
235
+ });
236
+ it("also caches for ECDb.withQueryReader (shared ECSqlRowExecutor path)", () => {
237
+ const env_1 = { stack: [], error: void 0, hasError: false };
238
+ try {
239
+ const ecdb = __addDisposableResource(env_1, ECDbTestHelper.createECDb(KnownTestLocations.outputDir, "syncReaderStmtCache.ecdb", `<ECSchema schemaName="Test" alias="ts" version="01.00.00" xmlns="http://www.bentley.com/schemas/Bentley.ECXML.3.2">
240
+ <ECEntityClass typeName="Foo" modifier="Sealed">
241
+ <ECProperty propertyName="n" typeName="int"/>
242
+ </ECEntityClass>
243
+ </ECSchema>`), false);
244
+ ecdb.saveChanges();
245
+ const ecdbSql = "SELECT ECInstanceId FROM meta.ECClassDef WHERE ECInstanceId=?";
246
+ const prepareSpy = sinon.spy(ECSqlStatement.prototype, "prepare"); // eslint-disable-line @typescript-eslint/no-deprecated
247
+ for (let i = 0; i < 10; i++)
248
+ ecdb.withQueryReader(ecdbSql, (reader) => reader.step(), new QueryBinder().bindId(1, "0x1"));
249
+ expect(prepareSpy.callCount).to.equal(1, "ECDb.withQueryReader should also reuse a cached prepared statement");
250
+ }
251
+ catch (e_1) {
252
+ env_1.error = e_1;
253
+ env_1.hasError = true;
254
+ }
255
+ finally {
256
+ __disposeResources(env_1);
257
+ }
258
+ });
259
+ });
122
260
  });
123
261
  //# sourceMappingURL=ECSqlSyncReader.test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ECSql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C;IACxB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","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 { assert, expect } from \"chai\";\nimport { QueryOptionsBuilder, QueryRowFormat } from \"@itwin/core-common\";\nimport { SnapshotDb } from \"../../IModelDb\";\nimport { IModelTestUtils } from \"../IModelTestUtils\";\nimport { Id64 } from \"@itwin/core-bentley\";\n\ndescribe(\"WithQueryReaderTests\", () => {\n let iModel: SnapshotDb;\n\n before(async () => {\n iModel = SnapshotDb.openFile(IModelTestUtils.resolveAssetFile(\"test.bim\"));\n });\n\n after(async () => {\n iModel.close();\n });\n it(\"check behvaiour if we call clearCaches in between\", () => {\n let actualRowCount = 0;\n const expectedInstanceIds = [\"0x1\", \"0xe\", \"0x10\", \"0x11\", \"0x12\",\n \"0x13\", \"0x14\", \"0x15\", \"0x16\", \"0x17\"];\n\n expect(() => iModel.withQueryReader(\"SELECT * FROM bis.Element\", (reader) => {\n let loopCount = 0;\n // First loop - read first 10 rows\n while (loopCount < 10) {\n reader.step()\n actualRowCount++;\n loopCount++;\n assert.isDefined(reader.current[0]);\n assert.equal(reader.current[0], expectedInstanceIds[actualRowCount - 1]);\n }\n assert.equal(loopCount, 10);\n iModel.clearCaches();\n\n reader.step(); // step should fail after clearCaches\n })).to.throw(\"Step failed\");\n });\n it(\"should throw error if we try to step on a closed iModelDb object\", () => {\n const imodelPath = iModel.pathName;\n expect(() => iModel.withQueryReader(\"SELECT * FROM bis.Element\", (reader) => {\n let loopCount = 0;\n while (loopCount < 10) {\n reader.step();\n assert.isDefined(reader.current[0]);\n loopCount++;\n }\n assert.equal(loopCount, 10);\n iModel.close();\n\n iModel = SnapshotDb.openFile(imodelPath);\n assert.isDefined(reader.current[0]);\n reader.step(); // step should fail after iModelDb is closed\n })).to.throw(\"Statement is not prepared\");\n });\n it(\"returning reader from withQueryReader callback should throw error if we try to step on it\", () => {\n const readerObj = iModel.withQueryReader(\"SELECT * FROM bis.Element\", (reader) => {\n reader.step();\n return reader;\n });\n expect(readerObj.current[0]).to.equal(\"0x1\"); // will not throw error as we are just accessing current row\n expect(() => readerObj.step()).to.throw(\"Statement is not prepared\");\n });\n it(\"checking rowFormat unspecified case - values accessed by index\", () => {\n // Default rowFormat is UseECSqlPropertyIndexes: columns are accessed by their SELECT-order index.\n iModel.withQueryReader(\"SELECT ECInstanceId, ECClassId FROM bis.Element\", (reader) => {\n assert.isTrue(reader.step());\n const id: string = reader.current[0];\n const classId: string = reader.current[1];\n assert.isTrue(Id64.isValid(classId));\n assert.isTrue(Id64.isValid(id));\n assert.equal(id, \"0x19\");\n });\n });\n\n it(\"checking rowFormat UseECSqlPropertyIndexes - values accessed by index\", () => {\n const config = new QueryOptionsBuilder().setRowFormat(QueryRowFormat.UseECSqlPropertyIndexes).getOptions();\n iModel.withQueryReader(\"SELECT ECInstanceId, ECClassId FROM bis.Element\", (reader) => {\n assert.isTrue(reader.step());\n // Index 0 → ECInstanceId, index 1 → ECClassId\n const id: string = reader.current[0];\n const classId: string = reader.current[1];\n assert.equal(id, \"0x19\");\n assert.isTrue(Id64.isValid(classId));\n // Swapping column order changes index, not value\n }, undefined, config);\n });\n\n it(\"checking rowFormat UseECSqlPropertyNames - values accessed by ECSQL property name\", () => {\n const config = new QueryOptionsBuilder().setRowFormat(QueryRowFormat.UseECSqlPropertyNames).getOptions();\n iModel.withQueryReader(\"SELECT ECInstanceId, ECClassId FROM bis.Element\", (reader) => {\n assert.isTrue(reader.step());\n const id: string = reader.current.ECInstanceId;\n const classId: string = reader.current.ECClassId;\n assert.equal(id, \"0x19\");\n assert.isTrue(Id64.isValid(classId));\n }, undefined, config);\n });\n\n it(\"checking rowFormat UseJsPropertyNames - values accessed by JavaScript property name\", () => {\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n const config = new QueryOptionsBuilder().setRowFormat(QueryRowFormat.UseJsPropertyNames).getOptions();\n iModel.withQueryReader(\"SELECT ECInstanceId, ECClassId FROM bis.Element\", (reader) => {\n assert.isTrue(reader.step());\n // ECInstanceId → id, ECClassId → className (resolved to a fully-qualified class name string)\n const id: string = reader.current.id;\n const className: string = reader.current.className;\n assert.equal(id, \"0x19\");\n // className should be in the form \"SchemaName.ClassName\"\n assert.equal(className, \"BisCore.DrawingCategory\");\n }, undefined, config);\n });\n\n it(\"checking rowFormat UseECSqlPropertyNames with convertClassIdsToClassNames - ECClassId returned as class name string\", () => {\n const config = new QueryOptionsBuilder()\n .setRowFormat(QueryRowFormat.UseECSqlPropertyNames)\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n .setConvertClassIdsToNames(true)\n .getOptions();\n iModel.withQueryReader(\"SELECT ECInstanceId, ECClassId FROM bis.Element\", (reader) => {\n assert.isTrue(reader.step());\n const id: string = reader.current.ECInstanceId;\n const classId: string = reader.current.ECClassId;\n assert.equal(id, \"0x19\");\n // With convertClassIdsToClassNames, ECClassId is resolved to \"SchemaName.ClassName\" instead of an Id\n assert.equal(classId, \"BisCore.DrawingCategory\");\n }, undefined, config);\n });\n});\n"]}
1
+ {"version":3,"file":"ECSqlSyncReader.test.js","sourceRoot":"","sources":["../../../../src/test/ecdb/ECSqlSyncReader.test.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE/F,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACtC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACtF,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,IAAI,EAAE,MAAM,q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,CAAC,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;YAC3F,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,mFAAmF,CAAC,CAAC;QAChI,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,qEAAqE,EAAE,GAAG,EAAE;;;gBAC7E,MAAM,IAAI,kCAAG,cAAc,CAAC,UAAU,CAAC,kBAAkB,CAAC,SAAS,EAAE,0BAA0B,EAC7F;;;;oBAIY,CAAC,QAAA,CAAC;gBAChB,IAAI,CAAC,WAAW,EAAE,CAAC;gBACnB,MAAM,OAAO,GAAG,+DAA+D,CAAC;gBAChF,MAAM,UAAU,GAAG,KAAK,CAAC,GAAG,CAAC,cAAc,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC,uDAAuD;gBAC1H,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE;oBACzB,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;gBAC/F,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,oEAAoE,CAAC,CAAC;;;;;;;;;SAChH,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","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 { assert, expect } from \"chai\";\nimport * as sinon from \"sinon\";\nimport { QueryBinder, QueryOptionsBuilder, QueryRowFormat } from \"@itwin/core-common\";\nimport { SnapshotDb } from \"../../IModelDb\";\nimport { IModelTestUtils } from \"../IModelTestUtils\";\nimport { Id64 } from \"@itwin/core-bentley\";\nimport { ECSqlStatement } from \"../../ECSqlStatement\";\nimport { ECDbTestHelper } from \"./ECDbTestHelper\";\nimport { KnownTestLocations } from \"../KnownTestLocations\";\n\ndescribe(\"WithQueryReaderTests\", () => {\n let iModel: SnapshotDb;\n\n before(async () => {\n iModel = SnapshotDb.openFile(IModelTestUtils.resolveAssetFile(\"test.bim\"));\n });\n\n after(async () => {\n iModel.close();\n });\n it(\"check behvaiour if we call clearCaches in between\", () => {\n let actualRowCount = 0;\n const expectedInstanceIds = [\"0x1\", \"0xe\", \"0x10\", \"0x11\", \"0x12\",\n \"0x13\", \"0x14\", \"0x15\", \"0x16\", \"0x17\"];\n\n expect(() => iModel.withQueryReader(\"SELECT * FROM bis.Element\", (reader) => {\n let loopCount = 0;\n // First loop - read first 10 rows\n while (loopCount < 10) {\n reader.step()\n actualRowCount++;\n loopCount++;\n assert.isDefined(reader.current[0]);\n assert.equal(reader.current[0], expectedInstanceIds[actualRowCount - 1]);\n }\n assert.equal(loopCount, 10);\n iModel.clearCaches();\n\n reader.step(); // step should fail after clearCaches\n })).to.throw(\"Step failed\");\n });\n it(\"should throw error if we try to step on a closed iModelDb object\", () => {\n const imodelPath = iModel.pathName;\n expect(() => iModel.withQueryReader(\"SELECT * FROM bis.Element\", (reader) => {\n let loopCount = 0;\n while (loopCount < 10) {\n reader.step();\n assert.isDefined(reader.current[0]);\n loopCount++;\n }\n assert.equal(loopCount, 10);\n iModel.close();\n\n iModel = SnapshotDb.openFile(imodelPath);\n assert.isDefined(reader.current[0]);\n reader.step(); // step should fail after iModelDb is closed\n })).to.throw(\"Statement is not prepared\");\n });\n it(\"returning reader from withQueryReader callback should throw error if we try to step on it\", () => {\n const readerObj = iModel.withQueryReader(\"SELECT * FROM bis.Element\", (reader) => {\n reader.step();\n return reader;\n });\n expect(readerObj.current[0]).to.equal(\"0x1\"); // will not throw error as we are just accessing current row\n expect(() => readerObj.step()).to.throw(\"Statement is not prepared\");\n });\n it(\"checking rowFormat unspecified case - values accessed by index\", () => {\n // Default rowFormat is UseECSqlPropertyIndexes: columns are accessed by their SELECT-order index.\n iModel.withQueryReader(\"SELECT ECInstanceId, ECClassId FROM bis.Element\", (reader) => {\n assert.isTrue(reader.step());\n const id: string = reader.current[0];\n const classId: string = reader.current[1];\n assert.isTrue(Id64.isValid(classId));\n assert.isTrue(Id64.isValid(id));\n assert.equal(id, \"0x19\");\n });\n });\n\n it(\"checking rowFormat UseECSqlPropertyIndexes - values accessed by index\", () => {\n const config = new QueryOptionsBuilder().setRowFormat(QueryRowFormat.UseECSqlPropertyIndexes).getOptions();\n iModel.withQueryReader(\"SELECT ECInstanceId, ECClassId FROM bis.Element\", (reader) => {\n assert.isTrue(reader.step());\n // Index 0 → ECInstanceId, index 1 → ECClassId\n const id: string = reader.current[0];\n const classId: string = reader.current[1];\n assert.equal(id, \"0x19\");\n assert.isTrue(Id64.isValid(classId));\n // Swapping column order changes index, not value\n }, undefined, config);\n });\n\n it(\"checking rowFormat UseECSqlPropertyNames - values accessed by ECSQL property name\", () => {\n const config = new QueryOptionsBuilder().setRowFormat(QueryRowFormat.UseECSqlPropertyNames).getOptions();\n iModel.withQueryReader(\"SELECT ECInstanceId, ECClassId FROM bis.Element\", (reader) => {\n assert.isTrue(reader.step());\n const id: string = reader.current.ECInstanceId;\n const classId: string = reader.current.ECClassId;\n assert.equal(id, \"0x19\");\n assert.isTrue(Id64.isValid(classId));\n }, undefined, config);\n });\n\n it(\"checking rowFormat UseJsPropertyNames - values accessed by JavaScript property name\", () => {\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n const config = new QueryOptionsBuilder().setRowFormat(QueryRowFormat.UseJsPropertyNames).getOptions();\n iModel.withQueryReader(\"SELECT ECInstanceId, ECClassId FROM bis.Element\", (reader) => {\n assert.isTrue(reader.step());\n // ECInstanceId → id, ECClassId → className (resolved to a fully-qualified class name string)\n const id: string = reader.current.id;\n const className: string = reader.current.className;\n assert.equal(id, \"0x19\");\n // className should be in the form \"SchemaName.ClassName\"\n assert.equal(className, \"BisCore.DrawingCategory\");\n }, undefined, config);\n });\n\n it(\"checking rowFormat UseECSqlPropertyNames with convertClassIdsToClassNames - ECClassId returned as class name string\", () => {\n const config = new QueryOptionsBuilder()\n .setRowFormat(QueryRowFormat.UseECSqlPropertyNames)\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n .setConvertClassIdsToNames(true)\n .getOptions();\n iModel.withQueryReader(\"SELECT ECInstanceId, ECClassId FROM bis.Element\", (reader) => {\n assert.isTrue(reader.step());\n const id: string = reader.current.ECInstanceId;\n const classId: string = reader.current.ECClassId;\n assert.equal(id, \"0x19\");\n // With convertClassIdsToClassNames, ECClassId is resolved to \"SchemaName.ClassName\" instead of an Id\n assert.equal(classId, \"BisCore.DrawingCategory\");\n }, undefined, config);\n });\n\n describe(\"statement caching (regression)\", () => {\n // `withQueryReader` used to build a fresh `ECSqlStatement` and re-compile the ECSQL on every\n // call (via `ECSqlRowExecutor`), with no caching. Callers such as `IModelTransformer` invoke\n // per-element helpers (e.g. `hasSubModel`) once per element, so on large models this turned one\n // cached ECSQL prepare into N full native compiles - a significant performance regression. The\n // reader now reuses a prepared statement from the owning db's `_statementCache`.\n const sql = \"SELECT ECInstanceId FROM bis.Element WHERE ECInstanceId=?\";\n\n afterEach(() => sinon.restore());\n\n it(\"reuses a single prepared statement across repeated calls instead of re-preparing\", () => {\n iModel.clearCaches();\n const prepareSpy = sinon.spy(ECSqlStatement.prototype, \"prepare\"); // eslint-disable-line @typescript-eslint/no-deprecated\n for (let i = 0; i < 20; i++) {\n iModel.withQueryReader(sql, (reader) => {\n reader.step();\n }, new QueryBinder().bindId(1, \"0x1\"));\n }\n expect(prepareSpy.callCount).to.equal(1, \"queries with identical ECSQL text should re-use one cached prepared statement\");\n });\n\n it(\"keeps nested withQueryReader calls on the same SQL independent\", () => {\n iModel.clearCaches();\n // A nested reader on the same SQL must get its own statement (findAndRemove hands the outer\n // reader's statement out of the cache), so results do not corrupt each other.\n const outerId = iModel.withQueryReader(sql, (outer) => {\n assert.isTrue(outer.step());\n const innerId = iModel.withQueryReader(sql, (inner) => {\n assert.isTrue(inner.step());\n return inner.current[0] as string;\n }, new QueryBinder().bindId(1, \"0xe\"));\n expect(innerId).to.equal(\"0xe\");\n // Outer reader's cursor must be unaffected by the nested reader.\n return outer.current[0] as string;\n }, new QueryBinder().bindId(1, \"0x1\"));\n expect(outerId).to.equal(\"0x1\");\n });\n\n it(\"recovers from a prepare failure without poisoning the cache\", () => {\n iModel.clearCaches();\n const invalidSql = \"SELECT * FROM bis.ThisClassDoesNotExist\";\n const prepareSpy = sinon.spy(ECSqlStatement.prototype, \"prepare\"); // eslint-disable-line @typescript-eslint/no-deprecated\n expect(() => iModel.withQueryReader(invalidSql, (reader) => reader.step())).to.throw();\n expect(() => iModel.withQueryReader(invalidSql, (reader) => reader.step())).to.throw();\n expect(prepareSpy.callCount).to.equal(2, \"a statement that failed to prepare must not be cached\");\n\n iModel.withQueryReader(sql, (reader) => {\n assert.isTrue(reader.step());\n expect(reader.current[0]).to.equal(\"0x1\");\n }, new QueryBinder().bindId(1, \"0x1\"));\n });\n\n it(\"releases the executor and cached statement when binding fails during reader construction\", () => {\n iModel.clearCaches();\n const prepareSpy = sinon.spy(ECSqlStatement.prototype, \"prepare\"); // eslint-disable-line @typescript-eslint/no-deprecated\n iModel.withQueryReader(sql, (reader) => reader.step(), new QueryBinder().bindId(1, \"0x1\"));\n const listenerCount = iModel.onBeforeClose.numberOfListeners;\n\n const bindStub = sinon.stub(ECSqlStatement.prototype, \"bindParams\").throws(new Error(\"Expected bind failure\")); // eslint-disable-line @typescript-eslint/no-deprecated\n expect(() => iModel.withQueryReader(sql, () => undefined, new QueryBinder().bindId(1, \"0x1\"))).to.throw(\"Expected bind failure\");\n bindStub.restore();\n expect(iModel.onBeforeClose.numberOfListeners).to.equal(listenerCount);\n\n iModel.withQueryReader(sql, (reader) => reader.step(), new QueryBinder().bindId(1, \"0x1\"));\n expect(prepareSpy.callCount).to.equal(1, \"the statement checked out before the bind failure should be returned to the cache\");\n });\n\n it(\"also caches for ECDb.withQueryReader (shared ECSqlRowExecutor path)\", () => {\n using ecdb = ECDbTestHelper.createECDb(KnownTestLocations.outputDir, \"syncReaderStmtCache.ecdb\",\n `<ECSchema schemaName=\"Test\" alias=\"ts\" version=\"01.00.00\" xmlns=\"http://www.bentley.com/schemas/Bentley.ECXML.3.2\">\n <ECEntityClass typeName=\"Foo\" modifier=\"Sealed\">\n <ECProperty propertyName=\"n\" typeName=\"int\"/>\n </ECEntityClass>\n </ECSchema>`);\n ecdb.saveChanges();\n const ecdbSql = \"SELECT ECInstanceId FROM meta.ECClassDef WHERE ECInstanceId=?\";\n const prepareSpy = sinon.spy(ECSqlStatement.prototype, \"prepare\"); // eslint-disable-line @typescript-eslint/no-deprecated\n for (let i = 0; i < 10; i++)\n ecdb.withQueryReader(ecdbSql, (reader) => reader.step(), new QueryBinder().bindId(1, \"0x1\"));\n expect(prepareSpy.callCount).to.equal(1, \"ECDb.withQueryReader should also reuse a cached prepared statement\");\n });\n });\n});\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itwin/core-backend",
3
- "version": "5.12.0-dev.15",
3
+ "version": "5.12.0-dev.16",
4
4
  "description": "iTwin.js backend components",
5
5
  "main": "lib/cjs/core-backend.js",
6
6
  "module": "lib/esm/core-backend.js",
@@ -27,10 +27,10 @@
27
27
  },
28
28
  "peerDependencies": {
29
29
  "@opentelemetry/api": "^1.0.4",
30
- "@itwin/core-bentley": "5.12.0-dev.15",
31
- "@itwin/core-geometry": "5.12.0-dev.15",
32
- "@itwin/ecschema-metadata": "5.12.0-dev.15",
33
- "@itwin/core-common": "5.12.0-dev.15"
30
+ "@itwin/core-bentley": "5.12.0-dev.16",
31
+ "@itwin/core-common": "5.12.0-dev.16",
32
+ "@itwin/core-geometry": "5.12.0-dev.16",
33
+ "@itwin/ecschema-metadata": "5.12.0-dev.16"
34
34
  },
35
35
  "peerDependenciesMeta": {
36
36
  "@opentelemetry/api": {
@@ -77,17 +77,17 @@
77
77
  "marked": "^14.1.3",
78
78
  "sql-formatter": "^15.4.6",
79
79
  "webpack": "^5.97.1",
80
- "@itwin/ecschema-metadata": "5.12.0-dev.15",
81
- "@itwin/build-tools": "5.12.0-dev.15",
82
- "@itwin/ecschema-locaters": "5.12.0-dev.15",
83
- "@itwin/core-bentley": "5.12.0-dev.15",
84
- "@itwin/core-common": "5.12.0-dev.15",
85
- "@itwin/core-geometry": "5.12.0-dev.15",
86
- "@itwin/ecsql-common": "5.12.0-dev.15",
87
- "internal-tools": "3.0.0-dev.69"
80
+ "@itwin/build-tools": "5.12.0-dev.16",
81
+ "@itwin/core-bentley": "5.12.0-dev.16",
82
+ "@itwin/core-common": "5.12.0-dev.16",
83
+ "@itwin/core-geometry": "5.12.0-dev.16",
84
+ "internal-tools": "3.0.0-dev.69",
85
+ "@itwin/ecschema-locaters": "5.12.0-dev.16",
86
+ "@itwin/ecsql-common": "5.12.0-dev.16",
87
+ "@itwin/ecschema-metadata": "5.12.0-dev.16"
88
88
  },
89
89
  "dependencies": {
90
- "@bentley/imodeljs-native": "5.12.23",
90
+ "@bentley/imodeljs-native": "5.12.26",
91
91
  "@itwin/object-storage-azure": "^3.0.4",
92
92
  "@azure/storage-blob": "^12.28.0",
93
93
  "form-data": "^4.0.6",