Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add definitionContainers to categories tree #1172

Open
wants to merge 44 commits into
base: master
Choose a base branch
from

Conversation

JonasDov
Copy link
Contributor

closes #1126

@JonasDov JonasDov requested review from a team as code owners January 31, 2025 18:01
Copy link
Member

@grigasp grigasp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Impressive set of tests - great work!

JonasDov and others added 24 commits February 3, 2025 15:31
…ees/categories-tree/internal/CategoriesTreeIdsCache.ts

Co-authored-by: Grigas <35135765+grigasp@users.noreply.github.com>
…ees/categories-tree/internal/CategoriesTreeIdsCache.ts

Co-authored-by: Grigas <35135765+grigasp@users.noreply.github.com>
…ees/categories-tree/internal/CategoriesTreeIdsCache.ts

Co-authored-by: Grigas <35135765+grigasp@users.noreply.github.com>
…ees/categories-tree/internal/CategoriesTreeNode.ts

Co-authored-by: Grigas <35135765+grigasp@users.noreply.github.com>
…ees/categories-tree/internal/CategoriesTreeNode.ts

Co-authored-by: Grigas <35135765+grigasp@users.noreply.github.com>
…rnal/CategoriesTreeIdsCache.test.ts

Co-authored-by: Grigas <35135765+grigasp@users.noreply.github.com>
…ees/categories-tree/CategoriesTreeDefinition.ts

Co-authored-by: Grigas <35135765+grigasp@users.noreply.github.com>
Comment on lines 57 to 62
const getCategoriesTreeIdsCache = useCallback(() => {
if (!idsCacheRef.current) {
idsCacheRef.current = new CategoriesTreeIdsCache(createECSqlQueryExecutor(iModel), viewType);
}
return idsCacheRef.current;
}, [viewType, iModel]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see where idsCacheRef.current is reset when view type or iModel changes so it will always return same cache.

Copy link
Contributor Author

@JonasDov JonasDov Feb 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, missed that, removed the condition, changed to useMemo

@grigasp
Copy link
Member

grigasp commented Feb 10, 2025

I created a test iModel to check query performance and noticed some worrying things.

The code to create a test iModel:

await buildIModel(this, async (builder) => {
  const physicalModel = insertPhysicalModelWithPartition({ builder, codeValue: "TestPhysicalModel" });

  for (let i = 0; i < 1000; ++i) {
    const definitionContainer = insertDefinitionContainer({ builder, codeValue: `Definition container ${i + 1}` });
    const definitionModel = insertSubModel({ builder, classFullName: "BisCore.DefinitionModel", modeledElementId: definitionContainer.id });
    if (i === 0) {
      for (let j = 0; j < 1000; ++j) {
        const definitionContainerChild = insertDefinitionContainer({
          builder,
          codeValue: `Child definition container ${j + 1}`,
          modelId: definitionModel.id,
        });
        const definitionModelChild = insertSubModel({ builder, classFullName: "BisCore.DefinitionModel", modeledElementId: definitionContainerChild.id });
        const category = insertSpatialCategory({ builder, codeValue: "Child category", modelId: definitionModelChild.id });
        insertPhysicalElement({ builder, modelId: physicalModel.id, categoryId: category.id });
      }
    } else if (i === 1) {
      for (let j = 0; j < 1000; ++j) {
        const category = insertSpatialCategory({ builder, codeValue: `Child category ${j + 1}`, modelId: definitionModel.id });
        insertPhysicalElement({ builder, modelId: physicalModel.id, categoryId: category.id });
      }
    } else if (i % 2 === 0) {
      const definitionContainerChild = insertDefinitionContainer({ builder, codeValue: "Child definition container", modelId: definitionModel.id });
      const definitionModelChild = insertSubModel({ builder, classFullName: "BisCore.DefinitionModel", modeledElementId: definitionContainerChild.id });
      const category = insertSpatialCategory({ builder, codeValue: "Child category", modelId: definitionModelChild.id });
      insertPhysicalElement({ builder, modelId: physicalModel.id, categoryId: category.id });
    } else {
      const category = insertSpatialCategory({ builder, codeValue: "Child category", modelId: definitionModel.id });
      insertPhysicalElement({ builder, modelId: physicalModel.id, categoryId: category.id });
    }
  }
});

Observations:

  1. Loading initial view takes ~4 seconds (our target is < 1 second).
  2. When loading initial view, the following query is executed twice:
    SELECT ECInstanceId as id FROM BisCore.SpatialCategory WHERE ECInstanceId IN (SELECT DISTINCT Category.Id as id from BisCore.GeometricElement3d WHERE Category.Id IN (SELECT ECInstanceId from BisCore.SpatialCategory))
  3. When loading initial view, the following query takes ~2.8 seconds:
    WITH RECURSIVE DefinitionContainers(ECInstanceId, ModelId) AS (
        SELECT dc.ECInstanceId, dc.Model.Id
        FROM BisCore.DefinitionContainer dc
        WHERE dc.ECInstanceId IN (0x13,0x17,0x1b,0x1f,0x23,0x27,0x2b,0x2f,0x33,0x37,0x3b,0x3f,0x43,0x47,0x4b,0x4f,0x53,0x57,0x5b,0x5f,0x63,0x67,0x6b,0x6f,0x73,0x77,0x7b,0x7f,0x83,0x87,0x8b,0x8f,0x93,0x97,0x9b,0x9f,0xa3,0xa7,0xab,0xaf,0xb3,0xb7,0xbb,0xbf,0xc3,0xc7,0xcb,0xcf,0xd3,0xd7,0xdb,0xdf,0xe3,0xe7,0xeb,0xef,0xf3,0xf7,0xfb,0xff,0x103,0x107,0x10b,0x10f,0x113,0x117,0x11b,0x11f,0x123,0x127,0x12b,0x12f,0x133,0x137,0x13b,0x13f,0x143,0x147,0x14b,0x14f,0x153,0x157,0x15b,0x15f,0x163,0x167,0x16b,0x16f,0x173,0x177,0x17b,0x17f,0x183,0x187,0x18b,0x18f,0x193,0x197,0x19b,0x19f,0x1a3,0x1a7,0x1ab,0x1af,0x1b3,0x1b7,0x1bb,0x1bf,0x1c3,0x1c7,0x1cb,0x1cf,0x1d3,0x1d7,0x1db,0x1df,0x1e3,0x1e7,0x1eb,0x1ef,0x1f3,0x1f7,0x1fb,0x1ff,0x203,0x207,0x20b,0x20f,0x213,0x217,0x21b,0x21f,0x223,0x227,0x22b,0x22f,0x233,0x237,0x23b,0x23f,0x243,0x247,0x24b,0x24f,0x253,0x257,0x25b,0x25f,0x263,0x267,0x26b,0x26f,0x273,0x277,0x27b,0x27f,0x283,0x287,0x28b,0x28f,0x293,0x297,0x29b,0x29f,0x2a3,0x2a7,0x2ab,0x2af,0x2b3,0x2b7,0x2bb,0x2bf,0x2c3,0x2c7,0x2cb,0x2cf,0x2d3,0x2d7,0x2db,0x2df,0x2e3,0x2e7,0x2eb,0x2ef,0x2f3,0x2f7,0x2fb,0x2ff,0x303,0x307,0x30b,0x30f,0x313,0x317,0x31b,0x31f,0x323,0x327,0x32b,0x32f,0x333,0x337,0x33b,0x33f,0x343,0x347,0x34b,0x34f,0x353,0x357,0x35b,0x35f,0x363,0x367,0x36b,0x36f,0x373,0x377,0x37b,0x37f,0x383,0x387,0x38b,0x38f,0x393,0x397,0x39b,0x39f,0x3a3,0x3a7,0x3ab,0x3af,0x3b3,0x3b7,0x3bb,0x3bf,0x3c3,0x3c7,0x3cb,0x3cf,0x3d3,0x3d7,0x3db,0x3df,0x3e3,0x3e7,0x3eb,0x3ef,0x3f3,0x3f7,0x3fb,0x3ff,0x403,0x407,0x40b,0x40f,0x413,0x417,0x41b,0x41f,0x423,0x427,0x42b,0x42f,0x433,0x437,0x43b,0x43f,0x443,0x447,0x44b,0x44f,0x453,0x457,0x45b,0x45f,0x463,0x467,0x46b,0x46f,0x473,0x477,0x47b,0x47f,0x483,0x487,0x48b,0x48f,0x493,0x497,0x49b,0x49f,0x4a3,0x4a7,0x4ab,0x4af,0x4b3,0x4b7,0x4bb,0x4bf,0x4c3,0x4c7,0x4cb,0x4cf,0x4d3,0x4d7,0x4db,0x4df,0x4e3,0x4e7,0x4eb,0x4ef,0x4f3,0x4f7,0x4fb,0x4ff,0x503,0x507,0x50b,0x50f,0x513,0x517,0x51b,0x51f,0x523,0x527,0x52b,0x52f,0x533,0x537,0x53b,0x53f,0x543,0x547,0x54b,0x54f,0x553,0x557,0x55b,0x55f,0x563,0x567,0x56b,0x56f,0x573,0x577,0x57b,0x57f,0x583,0x587,0x58b,0x58f,0x593,0x597,0x59b,0x59f,0x5a3,0x5a7,0x5ab,0x5af,0x5b3,0x5b7,0x5bb,0x5bf,0x5c3,0x5c7,0x5cb,0x5cf,0x5d3,0x5d7,0x5db,0x5df,0x5e3,0x5e7,0x5eb,0x5ef,0x5f3,0x5f7,0x5fb,0x5ff,0x603,0x607,0x60b,0x60f,0x613,0x617,0x61b,0x61f,0x623,0x627,0x62b,0x62f,0x633,0x637,0x63b,0x63f,0x643,0x647,0x64b,0x64f,0x653,0x657,0x65b,0x65f,0x663,0x667,0x66b,0x66f,0x673,0x677,0x67b,0x67f,0x683,0x687,0x68b,0x68f,0x693,0x697,0x69b,0x69f,0x6a3,0x6a7,0x6ab,0x6af,0x6b3,0x6b7,0x6bb,0x6bf,0x6c3,0x6c7,0x6cb,0x6cf,0x6d3,0x6d7,0x6db,0x6df,0x6e3,0x6e7,0x6eb,0x6ef,0x6f3,0x6f7,0x6fb,0x6ff,0x703,0x707,0x70b,0x70f,0x713,0x717,0x71b,0x71f,0x723,0x727,0x72b,0x72f,0x733,0x737,0x73b,0x73f,0x743,0x747,0x74b,0x74f,0x753,0x757,0x75b,0x75f,0x763,0x767,0x76b,0x76f,0x773,0x777,0x77b,0x77f,0x783,0x787,0x78b,0x78f,0x793,0x797,0x79b,0x79f,0x7a3,0x7a7,0x7ab,0x7af,0x7b3,0x7b7,0x7bb,0x7bf,0x7c3,0x7c7,0x7cb,0x7cf,0x7d3,0x7d7,0x7db,0x7df,0x7e3,0x7e7,0x7eb,0x7ef,0x7f3,0x7f7,0x7fb,0x7ff,0x803,0x807,0x80b,0x80f,0x813,0x817,0x81b,0x81f,0x823,0x827,0x82b,0x82f,0x833,0x837,0x83b,0x83f,0x843,0x847,0x84b,0x84f,0x853,0x857,0x85b,0x85f,0x863,0x867,0x86b,0x86f,0x873,0x877,0x87b,0x87f,0x883,0x887,0x88b,0x88f,0x893,0x897,0x89b,0x89f,0x8a3,0x8a7,0x8ab,0x8af,0x8b3,0x8b7,0x8bb,0x8bf,0x8c3,0x8c7,0x8cb,0x8cf,0x8d3,0x8d7,0x8db,0x8df,0x8e3,0x8e7,0x8eb,0x8ef,0x8f3,0x8f7,0x8fb,0x8ff,0x903,0x907,0x90b,0x90f,0x913,0x917,0x91b,0x91f,0x923,0x927,0x92b,0x92f,0x933,0x937,0x93b,0x93f,0x943,0x947,0x94b,0x94f,0x953,0x957,0x95b,0x95f,0x963,0x967,0x96b,0x96f,0x973,0x977,0x97b,0x97f,0x983,0x987,0x98b,0x98f,0x993,0x997,0x99b,0x99f,0x9a3,0x9a7,0x9ab,0x9af,0x9b3,0x9b7,0x9bb,0x9bf,0x9c3,0x9c7,0x9cb,0x9cf,0x9d3,0x9d7,0x9db,0x9df,0x9e3,0x9e7,0x9eb,0x9ef,0x9f3,0x9f7,0x9fb,0x9ff,0xa03,0xa07,0xa0b,0xa0f,0xa13,0xa17,0xa1b,0xa1f,0xa23,0xa27,0xa2b,0xa2f,0xa33,0xa37,0xa3b,0xa3f,0xa43,0xa47,0xa4b,0xa4f,0xa53,0xa57,0xa5b,0xa5f,0xa63,0xa67,0xa6b,0xa6f,0xa73,0xa77,0xa7b,0xa7f,0xa83,0xa87,0xa8b,0xa8f,0xa93,0xa97,0xa9b,0xa9f,0xaa3,0xaa7,0xaab,0xaaf,0xab3,0xab7,0xabb,0xabf,0xac3,0xac7,0xacb,0xacf,0xad3,0xad7,0xadb,0xadf,0xae3,0xae7,0xaeb,0xaef,0xaf3,0xaf7,0xafb,0xaff,0xb03,0xb07,0xb0b,0xb0f,0xb13,0xb17,0xb1b,0xb1f,0xb23,0xb27,0xb2b,0xb2f,0xb33,0xb37,0xb3b,0xb3f,0xb43,0xb47,0xb4b,0xb4f,0xb53,0xb57,0xb5b,0xb5f,0xb63,0xb67,0xb6b,0xb6f,0xb73,0xb77,0xb7b,0xb7f,0xb83,0xb87,0xb8b,0xb8f,0xb93,0xb97,0xb9b,0xb9f,0xba3,0xba7,0xbab,0xbaf,0xbb3,0xbb7,0xbbb,0xbbf,0xbc3,0xbc7,0xbcb,0xbcf,0xbd3,0xbd7,0xbdb,0xbdf,0xbe3,0xbe7,0xbeb,0xbef,0xbf3,0xbf7,0xbfb,0xbff,0xc03,0xc07,0xc0b,0xc0f,0xc13,0xc17,0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0x1d84,0x1d89,0x1d8d,0x1d92,0x1d96,0x1d9b,0x1d9f,0x1da4,0x1da8,0x1dad,0x1db1,0x1db6,0x1dba,0x1dbf,0x1dc3,0x1dc8,0x1dcc,0x1dd1,0x1dd5,0x1dda,0x1dde,0x1de3,0x1de7,0x1dec,0x1df0,0x1df5,0x1df9,0x1dfe,0x1e02,0x1e07,0x1e0b,0x1e10,0x1e14,0x1e19,0x1e1d,0x1e22,0x1e26,0x1e2b,0x1e2f,0x1e34,0x1e38,0x1e3d,0x1e41,0x1e46,0x1e4a,0x1e4f,0x1e53,0x1e58,0x1e5c,0x1e61,0x1e65,0x1e6a,0x1e6e,0x1e73,0x1e77,0x1e7c,0x1e80,0x1e85,0x1e89,0x1e8e,0x1e92,0x1e97,0x1e9b,0x1ea0,0x1ea4,0x1ea9,0x1ead,0x1eb2,0x1eb6,0x1ebb,0x1ebf,0x1ec4,0x1ec8,0x1ecd,0x1ed1,0x1ed6,0x1eda,0x1edf,0x1ee3,0x1ee8,0x1eec,0x1ef1,0x1ef5,0x1efa,0x1efe,0x1f03,0x1f07,0x1f0c,0x1f10,0x1f15,0x1f19,0x1f1e,0x1f22,0x1f27,0x1f2b,0x1f30,0x1f34,0x1f39,0x1f3d,0x1f42,0x1f46,0x1f4b,0x1f4f,0x1f54,0x1f58,0x1f5d,0x1f61,0x1f66,0x1f6a,0x1f6f,0x1f73,0x1f78,0x1f7c,0x1f81,0x1f85,0x1f8a,0x1f8e,0x1f93,0x1f97,0x1f9c,0x1fa0,0x1fa5,0x1fa9,0x1fae,0x1fb2,0x1fb7,0x1fbb,0x1fc0,0x1fc4,0x1fc9,0x1fcd,0x1fd2,0x1fd6,0x1fdb,0x1fdf,0x1fe4,0x1fe8,0x1fed,0x1ff1,0x1ff6,0x1ffa,0x1fff,0x2003,0x2008,0x200c,0x2011,0x2015,0x201a,0x201e,0x2023,0x2027,0x202c,0x2030,0x2035,0x2039,0x203e,0x2042,0x2047,0x204b,0x2050,0x2054,0x2059,0x205d,0x2062,0x2066,0x206b,0x206f,0x2074,0x2078,0x207d,0x2081,0x2086,0x208a,0x208f,0x2093,0x2098,0x209c,0x20a1,0x20a5,0x20aa,0x20ae,0x20b3,0x20b7,0x20bc,0x20c0,0x20c5,0x20c9,0x20ce,0x20d2,0x20d7,0x20db,0x20e0,0x20e4,0x20e9,0x20ed,0x20f2,0x20f6,0x20fb,0x20ff,0x2104,0x2108,0x210d,0x2111,0x2116,0x211a,0x211f,0x2123,0x2128,0x212c,0x2131,0x2135,0x213a,0x213e,0x2143,0x2147,0x214c,0x2150,0x2155,0x2159,0x215e,0x2162,0x2167,0x216b,0x2170,0x2174,0x2179,0x217d,0x2182,0x2186,0x218b,0x218f,0x2194,0x2198,0x219d,0x21a1,0x21a6,0x21aa,0x21af,0x21b3,0x21b8,0x21bc,0x21c1,0x21c5,0x21ca,0x21ce,0x21d3,0x21d7,0x21dc,0x21e0,0x21e5,0x21e9,0x21ee,0x21f2,0x21f7,0x21fb,0x2200,0x2204,0x2209,0x220d,0x2212,0x2216,0x221b,0x221f,0x2224,0x2228,0x222d,0x2231,0x2236,0x223a,0x223f,0x2243,0x2248,0x224c,0x2251,0x2255,0x225a,0x225e,0x2263,0x2267,0x226c,0x2270,0x2275,0x2279,0x227e,0x2282,0x2287,0x228b,0x2290,0x2294,0x2299,0x229d,0x22a2,0x22a6,0x22ab,0x22af,0x22b4,0x22b8,0x22bd,0x22c1,0x22c6,0x22ca,0x22cf,0x22d3,0x22d8,0x22dc,0x22e1,0x22e5,0x22ea,0x22ee,0x22f3,0x22f7,0x22fc,0x2300,0x2305,0x2309,0x230e,0x2312,0x2317,0x231b,0x2320,0x2324,0x2329,0x232d,0x2332,0x2336,0x233b,0x233f,0x2344,0x2348,0x234d,0x2351,0x2356,0x235a,0x235f,0x2363,0x2368,0x236c,0x2371,0x2375,0x237a,0x237e,0x2383,0x2387,0x238c,0x2390,0x2395,0x2399,0x239e,0x23a2,0x23a7,0x23ab,0x23b0,0x23b4,0x23b9,0x23bd,0x23c2,0x23c6,0x23cb,0x23cf,0x23d4,0x23d8,0x23dd,0x23e1,0x23e6,0x23ea,0x23ef,0x23f3,0x23f8,0x23fc,0x2401,0x2405,0x240a,0x240e,0x2413,0x2417,0x241c,0x2420,0x2425,0x2429,0x242e,0x2432,0x2437,0x243b,0x2440,0x2444,0x2449,0x244d,0x2452,0x2456,0x245b,0x245f,0x2464,0x2468,0x246d,0x2471,0x2476,0x247a,0x247f,0x2483,0x2488,0x248c,0x2491,0x2495,0x249a,0x249e,0x24a3,0x24a7,0x24ac,0x24b0,0x24b5,0x24b9,0x24be,0x24c2,0x24c7,0x24cb,0x24d0,0x24d4,0x24d9,0x24dd,0x24e2,0x24e6,0x24eb,0x24ef,0x24f4,0x24f8,0x24fd,0x2501,0x2506,0x250a,0x250f,0x2513,0x2518,0x251c,0x2521,0x2525,0x252a,0x252e,0x2533,0x2537,0x253c,0x2540,0x2545,0x2549,0x254e,0x2552,0x2557,0x255b,0x2560,0x2564,0x2569,0x256d,0x2572,0x2576,0x257b,0x257f,0x2584,0x2588,0x258d,0x2591,0x2596,0x259a,0x259f,0x25a3,0x25a8,0x25ac,0x25b1,0x25b5,0x25ba,0x25be,0x25c3,0x25c7,0x25cc,0x25d0,0x25d5,0x25d9,0x25de,0x25e2,0x25e7,0x25eb,0x25f0,0x25f4,0x25f9,0x25fd,0x2602,0x2606,0x260b,0x260f,0x2614,0x2618,0x261d,0x2621,0x2626,0x262a,0x262f,0x2633,0x2638,0x263c,0x2641,0x2645,0x264a,0x264e,0x2653,0x2657,0x265c,0x2660,0x2665,0x2669,0x266e,0x2672,0x2677,0x267b,0x2680,0x2684,0x2689,0x268d,0x2692,0x2696,0x269b,0x269f,0x26a4,0x26a8,0x26ad,0x26b1,0x26b6,0x26ba,0x26bf,0x26c3,0x26c8,0x26cc,0x26d1,0x26d5,0x26da,0x26de,0x26e3,0x26e7,0x26ec,0x26f0,0x26f5,0x26f9,0x26fe,0x2702,0x2707,0x270b,0x2710,0x2714,0x2719,0x271d,0x2722,0x2726,0x272b,0x272f,0x2734,0x2738,0x273d,0x2741,0x2746,0x274a,0x274f,0x2753,0x2758,0x275c,0x2761,0x2765,0x276a,0x276e,0x2773,0x2777,0x277c,0x2780,0x2785,0x2789,0x278e,0x2792,0x2797,0x279b,0x27a0,0x27a4,0x27a9,0x27ad,0x27b2,0x27b6,0x27bb,0x27bf,0x27c4,0x27c8,0x27cd,0x27d1,0x27d6,0x27da,0x27df,0x27e3,0x27e8,0x27ec,0x27f1,0x27f5,0x27fa,0x27fe,0x2803,0x2807,0x280c,0x2810,0x2815,0x2819,0x281e,0x2822,0x2827,0x282b,0x2830,0x2834,0x2839,0x283d,0x2842,0x2846,0x284b,0x284f,0x2854,0x2858,0x285d,0x2861,0x2866,0x286a,0x286f,0x2873,0x2878,0x287c,0x2881,0x2885,0x288a,0x288e,0x2893,0x2897,0x289c,0x28a0,0x28a5,0x28a9,0x28ae,0x28b2,0x28b7,0x28bb,0x28c0,0x28c4,0x28c9,0x28cd,0x28d2,0x28d6,0x28db,0x28df,0x28e4,0x28e8,0x28ed,0x28f1,0x28f6,0x28fa,0x28ff,0x2903,0x2908,0x290c,0x2911,0x2915,0x291a,0x291e,0x2923,0x2927,0x292c,0x2930,0x2935,0x2939,0x293e,0x2942,0x2947,0x294b,0x2950,0x2954,0x2959,0x295d,0x2962,0x2966,0x296b,0x296f,0x2974,0x2978,0x297d,0x2981,0x2986,0x298a,0x298f,0x2993,0x2998,0x299c,0x29a1,0x29a5,0x29aa,0x29ae,0x29b3,0x29b7,0x29bc,0x29c0,0x29c5,0x29c9,0x29ce,0x29d2,0x29d7,0x29db,0x29e0,0x29e4,0x29e9,0x29ed,0x29f2,0x29f6,0x29fb,0x29ff,0x2a04,0x2a08,0x2a0d,0x2a11,0x2a16,0x2a1a,0x2a1f,0x2a23,0x2a28,0x2a2c,0x2a31,0x2a35,0x2a3a,0x2a3e,0x2a43,0x2a47,0x2a4c,0x2a50,0x2a55,0x2a59,0x2a5e,0x2a62,0x2a67,0x2a6b,0x2a70,0x2a74,0x2a79,0x2a7d,0x2a82,0x2a86,0x2a8b,0x2a8f,0x2a94,0x2a98,0x2a9d,0x2aa1,0x2aa6,0x2aaa,0x2aaf,0x2ab3,0x2ab8,0x2abc,0x2ac1,0x2ac5,0x2aca,0x2ace,0x2ad3,0x2ad7,0x2adc,0x2ae0,0x2ae5,0x2ae9,0x2aee,0x2af2,0x2af7,0x2afb,0x2b00,0x2b04,0x2b09,0x2b0d,0x2b12,0x2b16,0x2b1b,0x2b1f,0x2b24,0x2b28,0x2b2d,0x2b31,0x2b36,0x2b3a,0x2b3f,0x2b43,0x2b48,0x2b4c,0x2b51,0x2b55,0x2b5a,0x2b5e,0x2b63,0x2b67,0x2b6c,0x2b70,0x2b75,0x2b79,0x2b7e,0x2b82,0x2b87,0x2b8b,0x2b90,0x2b94,0x2b99,0x2b9d,0x2ba2,0x2ba6,0x2bab,0x2baf,0x2bb4,0x2bb8,0x2bbd,0x2bc1,0x2bc6,0x2bca,0x2bcf,0x2bd3,0x2bd8,0x2bdc,0x2be1,0x2be5,0x2bea,0x2bee,0x2bf3,0x2bf7,0x2bfc,0x2c00,0x2c05,0x2c09,0x2c0e,0x2c12,0x2c17,0x2c1b,0x2c20,0x2c24,0x2c29,0x2c2d,0x2c32,0x2c36,0x2c3b,0x2c3f,0x2c44,0x2c48,0x2c4d,0x2c51,0x2c56,0x2c5a,0x2c5f,0x2c63,0x2c68,0x2c6c,0x2c71,0x2c75,0x2c7a,0x2c7e,0x2c83,0x2c87,0x2c8c,0x2c90,0x2c95,0x2c99,0x2c9e,0x2ca2,0x2ca7,0x2cab,0x2cb0,0x2cb4,0x2cb9,0x2cbd,0x2cc2,0x2cc6,0x2ccb,0x2ccf,0x2cd4,0x2cd8,0x2cdd,0x2ce1,0x2ce6,0x2cea,0x2cef,0x2cf3)
            AND NOT dc.IsPrivate
        UNION ALL
        SELECT pdc.ECInstanceId, pdc.Model.Id
        FROM DefinitionContainers cdc
        JOIN BisCore.DefinitionContainer pdc ON pdc.ECInstanceId = cdc.ModelId
        WHERE NOT pdc.IsPrivate
    )
    SELECT dc.ECInstanceId id, dc.ModelId modelId
    FROM DefinitionContainers dc
    GROUP BY dc.ECInstanceId
  4. When loading initial view, the following query with recursive CTE is executed, but it doesn't look like CTE is needed.
       WITH RECURSIVE 
        AllVisibleCategories(ECInstanceId, ChildCount, ModelId, ParentDefinitionContainerExists) AS (
            SELECT this.ECInstanceId, COUNT(sc.ECInstanceId), this.Model.Id, IIF(this.Model.Id IN (SELECT dc.ECInstanceId FROM BisCore.DefinitionContainer dc), true, false) 
            FROM BisCore.SpatialCategory this 
            JOIN BisCore.SubCategory sc ON sc.Parent.Id = this.ECInstanceId 
            JOIN BisCore.Model m ON m.ECInstanceId = this.Model.Id 
            WHERE NOT this.IsPrivate AND (NOT m.IsPrivate OR m.ECClassId IS (BisCore.DictionaryModel)) 
                AND EXISTS (
                    SELECT 1 FROM BisCore.GeometricElement3d e 
                    WHERE e.Category.Id = this.ECInstanceId
                ) 
            GROUP BY this.ECInstanceId
        ) 
    SELECT this.ECInstanceId id, this.ModelId modelId, this.ParentDefinitionContainerExists parentDefinitionContainerExists, this.ChildCount childCount 
    FROM AllVisibleCategories this
  5. When loading children for "Definition container 2", containing 1000 child categories, the following query takes ~630 ms:
    SELECT *
    FROM (
            SELECT ec_ClassName([this].[ECClassId]) AS FullClassName,
                this.ECInstanceId AS ECInstanceId,
                COALESCE(
                    IIF(
                        [this].[ECClassId] IS (BisCore.Element),
                        COALESCE([this].[UserLabel], [this].[CodeValue]),
                        NULL
                    ),
                    (
                        SELECT json_array(
                                COALESCE([c].[DisplayLabel], [c].[Name]),
                                json_object('value', ' [', 'type', 'String'),
                                CAST(base36([this].[ECInstanceId] >> 40) AS TEXT),
                                json_object('value', '-', 'type', 'String'),
                                CAST(
                                    base36([this].[ECInstanceId] & ((1 << 40) - 1)) AS TEXT
                                ),
                                json_object('value', ']', 'type', 'String')
                            )
                        FROM [meta].[ECClassDef] AS [c]
                        WHERE [c].[ECInstanceId] = [this].[ECClassId]
                    )
                ) AS DisplayLabel,
                CAST(
                    IFNULL(
                        (
                            SELECT 1
                            FROM (
                                    SELECT COUNT(1) AS ChildCount
                                    FROM BisCore.SubCategory sc
                                    WHERE sc.Parent.Id = this.ECInstanceId
                                )
                            WHERE ChildCount > 1
                        ),
                        0
                    ) AS BOOLEAN
                ) AS HasChildren,
                CAST(NULL AS BOOLEAN) AS HideIfNoChildren,
                CAST(NULL AS BOOLEAN) AS HideNodeInHierarchy,
                CAST(NULL AS TEXT) AS Grouping,
                json_object(
                    'description',
                    this.Description,
                    'isCategory',
                    TRUE,
                    'imageId',
                    'icon-layers'
                ) AS ExtendedData,
                CAST(NULL AS BOOLEAN) AS AutoExpand,
                CAST(TRUE AS BOOLEAN) AS SupportsFiltering
            FROM BisCore.SpatialCategory this
            WHERE this.ECInstanceId IN (0xfb4,0xfb7,0xfba,0xfbd,0xfc0,0xfc3,0xfc6,0xfc9,0xfcc,0xfcf,0xfd2,0xfd5,0xfd8,0xfdb,0xfde,0xfe1,0xfe4,0xfe7,0xfea,0xfed,0xff0,0xff3,0xff6,0xff9,0xffc,0xfff,0x1002,0x1005,0x1008,0x100b,0x100e,0x1011,0x1014,0x1017,0x101a,0x101d,0x1020,0x1023,0x1026,0x1029,0x102c,0x102f,0x1032,0x1035,0x1038,0x103b,0x103e,0x1041,0x1044,0x1047,0x104a,0x104d,0x1050,0x1053,0x1056,0x1059,0x105c,0x105f,0x1062,0x1065,0x1068,0x106b,0x106e,0x1071,0x1074,0x1077,0x107a,0x107d,0x1080,0x1083,0x1086,0x1089,0x108c,0x108f,0x1092,0x1095,0x1098,0x109b,0x109e,0x10a1,0x10a4,0x10a7,0x10aa,0x10ad,0x10b0,0x10b3,0x10b6,0x10b9,0x10bc,0x10bf,0x10c2,0x10c5,0x10c8,0x10cb,0x10ce,0x10d1,0x10d4,0x10d7,0x10da,0x10dd,0x10e0,0x10e3,0x10e6,0x10e9,0x10ec,0x10ef,0x10f2,0x10f5,0x10f8,0x10fb,0x10fe,0x1101,0x1104,0x1107,0x110a,0x110d,0x1110,0x1113,0x1116,0x1119,0x111c,0x111f,0x1122,0x1125,0x1128,0x112b,0x112e,0x1131,0x1134,0x1137,0x113a,0x113d,0x1140,0x1143,0x1146,0x1149,0x114c,0x114f,0x1152,0x1155,0x1158,0x115b,0x115e,0x1161,0x1164,0x1167,0x116a,0x116d,0x1170,0x1173,0x1176,0x1179,0x117c,0x117f,0x1182,0x1185,0x1188,0x118b,0x118e,0x1191,0x1194,0x1197,0x119a,0x119d,0x11a0,0x11a3,0x11a6,0x11a9,0x11ac,0x11af,0x11b2,0x11b5,0x11b8,0x11bb,0x11be,0x11c1,0x11c4,0x11c7,0x11ca,0x11cd,0x11d0,0x11d3,0x11d6,0x11d9,0x11dc,0x11df,0x11e2,0x11e5,0x11e8,0x11eb,0x11ee,0x11f1,0x11f4,0x11f7,0x11fa,0x11fd,0x1200,0x1203,0x1206,0x1209,0x120c,0x120f,0x1212,0x1215,0x1218,0x121b,0x121e,0x1221,0x1224,0x1227,0x122a,0x122d,0x1230,0x1233,0x1236,0x1239,0x123c,0x123f,0x1242,0x1245,0x1248,0x124b,0x124e,0x1251,0x1254,0x1257,0x125a,0x125d,0x1260,0x1263,0x1266,0x1269,0x126c,0x126f,0x1272,0x1275,0x1278,0x127b,0x127e,0x1281,0x1284,0x1287,0x128a,0x128d,0x1290,0x1293,0x1296,0x1299,0x129c,0x129f,0x12a2,0x12a5,0x12a8,0x12ab,0x12ae,0x12b1,0x12b4,0x12b7,0x12ba,0x12bd,0x12c0,0x12c3,0x12c6,0x12c9,0x12cc,0x12cf,0x12d2,0x12d5,0x12d8,0x12db,0x12de,0x12e1,0x12e4,0x12e7,0x12ea,0x12ed,0x12f0,0x12f3,0x12f6,0x12f9,0x12fc,0x12ff,0x1302,0x1305,0x1308,0x130b,0x130e,0x1311,0x1314,0x1317,0x131a,0x131d,0x1320,0x1323,0x1326,0x1329,0x132c,0x132f,0x1332,0x1335,0x1338,0x133b,0x133e,0x1341,0x1344,0x1347,0x134a,0x134d,0x1350,0x1353,0x1356,0x1359,0x135c,0x135f,0x1362,0x1365,0x1368,0x136b,0x136e,0x1371,0x1374,0x1377,0x137a,0x137d,0x1380,0x1383,0x1386,0x1389,0x138c,0x138f,0x1392,0x1395,0x1398,0x139b,0x139e,0x13a1,0x13a4,0x13a7,0x13aa,0x13ad,0x13b0,0x13b3,0x13b6,0x13b9,0x13bc,0x13bf,0x13c2,0x13c5,0x13c8,0x13cb,0x13ce,0x13d1,0x13d4,0x13d7,0x13da,0x13dd,0x13e0,0x13e3,0x13e6,0x13e9,0x13ec,0x13ef,0x13f2,0x13f5,0x13f8,0x13fb,0x13fe,0x1401,0x1404,0x1407,0x140a,0x140d,0x1410,0x1413,0x1416,0x1419,0x141c,0x141f,0x1422,0x1425,0x1428,0x142b,0x142e,0x1431,0x1434,0x1437,0x143a,0x143d,0x1440,0x1443,0x1446,0x1449,0x144c,0x144f,0x1452,0x1455,0x1458,0x145b,0x145e,0x1461,0x1464,0x1467,0x146a,0x146d,0x1470,0x1473,0x1476,0x1479,0x147c,0x147f,0x1482,0x1485,0x1488,0x148b,0x148e,0x1491,0x1494,0x1497,0x149a,0x149d,0x14a0,0x14a3,0x14a6,0x14a9,0x14ac,0x14af,0x14b2,0x14b5,0x14b8,0x14bb,0x14be,0x14c1,0x14c4,0x14c7,0x14ca,0x14cd,0x14d0,0x14d3,0x14d6,0x14d9,0x14dc,0x14df,0x14e2,0x14e5,0x14e8,0x14eb,0x14ee,0x14f1,0x14f4,0x14f7,0x14fa,0x14fd,0x1500,0x1503,0x1506,0x1509,0x150c,0x150f,0x1512,0x1515,0x1518,0x151b,0x151e,0x1521,0x1524,0x1527,0x152a,0x152d,0x1530,0x1533,0x1536,0x1539,0x153c,0x153f,0x1542,0x1545,0x1548,0x154b,0x154e,0x1551,0x1554,0x1557,0x155a,0x155d,0x1560,0x1563,0x1566,0x1569,0x156c,0x156f,0x1572,0x1575,0x1578,0x157b,0x157e,0x1581,0x1584,0x1587,0x158a,0x158d,0x1590,0x1593,0x1596,0x1599,0x159c,0x159f,0x15a2,0x15a5,0x15a8,0x15ab,0x15ae,0x15b1,0x15b4,0x15b7,0x15ba,0x15bd,0x15c0,0x15c3,0x15c6,0x15c9,0x15cc,0x15cf,0x15d2,0x15d5,0x15d8,0x15db,0x15de,0x15e1,0x15e4,0x15e7,0x15ea,0x15ed,0x15f0,0x15f3,0x15f6,0x15f9,0x15fc,0x15ff,0x1602,0x1605,0x1608,0x160b,0x160e,0x1611,0x1614,0x1617,0x161a,0x161d,0x1620,0x1623,0x1626,0x1629,0x162c,0x162f,0x1632,0x1635,0x1638,0x163b,0x163e,0x1641,0x1644,0x1647,0x164a,0x164d,0x1650,0x1653,0x1656,0x1659,0x165c,0x165f,0x1662,0x1665,0x1668,0x166b,0x166e,0x1671,0x1674,0x1677,0x167a,0x167d,0x1680,0x1683,0x1686,0x1689,0x168c,0x168f,0x1692,0x1695,0x1698,0x169b,0x169e,0x16a1,0x16a4,0x16a7,0x16aa,0x16ad,0x16b0,0x16b3,0x16b6,0x16b9,0x16bc,0x16bf,0x16c2,0x16c5,0x16c8,0x16cb,0x16ce,0x16d1,0x16d4,0x16d7,0x16da,0x16dd,0x16e0,0x16e3,0x16e6,0x16e9,0x16ec,0x16ef,0x16f2,0x16f5,0x16f8,0x16fb,0x16fe,0x1701,0x1704,0x1707,0x170a,0x170d,0x1710,0x1713,0x1716,0x1719,0x171c,0x171f,0x1722,0x1725,0x1728,0x172b,0x172e,0x1731,0x1734,0x1737,0x173a,0x173d,0x1740,0x1743,0x1746,0x1749,0x174c,0x174f,0x1752,0x1755,0x1758,0x175b,0x175e,0x1761,0x1764,0x1767,0x176a,0x176d,0x1770,0x1773,0x1776,0x1779,0x177c,0x177f,0x1782,0x1785,0x1788,0x178b,0x178e,0x1791,0x1794,0x1797,0x179a,0x179d,0x17a0,0x17a3,0x17a6,0x17a9,0x17ac,0x17af,0x17b2,0x17b5,0x17b8,0x17bb,0x17be,0x17c1,0x17c4,0x17c7,0x17ca,0x17cd,0x17d0,0x17d3,0x17d6,0x17d9,0x17dc,0x17df,0x17e2,0x17e5,0x17e8,0x17eb,0x17ee,0x17f1,0x17f4,0x17f7,0x17fa,0x17fd,0x1800,0x1803,0x1806,0x1809,0x180c,0x180f,0x1812,0x1815,0x1818,0x181b,0x181e,0x1821,0x1824,0x1827,0x182a,0x182d,0x1830,0x1833,0x1836,0x1839,0x183c,0x183f,0x1842,0x1845,0x1848,0x184b,0x184e,0x1851,0x1854,0x1857,0x185a,0x185d,0x1860,0x1863,0x1866,0x1869,0x186c,0x186f,0x1872,0x1875,0x1878,0x187b,0x187e,0x1881,0x1884,0x1887,0x188a,0x188d,0x1890,0x1893,0x1896,0x1899,0x189c,0x189f,0x18a2,0x18a5,0x18a8,0x18ab,0x18ae,0x18b1,0x18b4,0x18b7,0x18ba,0x18bd,0x18c0,0x18c3,0x18c6,0x18c9,0x18cc,0x18cf,0x18d2,0x18d5,0x18d8,0x18db,0x18de,0x18e1,0x18e4,0x18e7,0x18ea,0x18ed,0x18f0,0x18f3,0x18f6,0x18f9,0x18fc,0x18ff,0x1902,0x1905,0x1908,0x190b,0x190e,0x1911,0x1914,0x1917,0x191a,0x191d,0x1920,0x1923,0x1926,0x1929,0x192c,0x192f,0x1932,0x1935,0x1938,0x193b,0x193e,0x1941,0x1944,0x1947,0x194a,0x194d,0x1950,0x1953,0x1956,0x1959,0x195c,0x195f,0x1962,0x1965,0x1968,0x196b,0x196e,0x1971,0x1974,0x1977,0x197a,0x197d,0x1980,0x1983,0x1986,0x1989,0x198c,0x198f,0x1992,0x1995,0x1998,0x199b,0x199e,0x19a1,0x19a4,0x19a7,0x19aa,0x19ad,0x19b0,0x19b3,0x19b6,0x19b9,0x19bc,0x19bf,0x19c2,0x19c5,0x19c8,0x19cb,0x19ce,0x19d1,0x19d4,0x19d7,0x19da,0x19dd,0x19e0,0x19e3,0x19e6,0x19e9,0x19ec,0x19ef,0x19f2,0x19f5,0x19f8,0x19fb,0x19fe,0x1a01,0x1a04,0x1a07,0x1a0a,0x1a0d,0x1a10,0x1a13,0x1a16,0x1a19,0x1a1c,0x1a1f,0x1a22,0x1a25,0x1a28,0x1a2b,0x1a2e,0x1a31,0x1a34,0x1a37,0x1a3a,0x1a3d,0x1a40,0x1a43,0x1a46,0x1a49,0x1a4c,0x1a4f,0x1a52,0x1a55,0x1a58,0x1a5b,0x1a5e,0x1a61,0x1a64,0x1a67,0x1a6a,0x1a6d,0x1a70,0x1a73,0x1a76,0x1a79,0x1a7c,0x1a7f,0x1a82,0x1a85,0x1a88,0x1a8b,0x1a8e,0x1a91,0x1a94,0x1a97,0x1a9a,0x1a9d,0x1aa0,0x1aa3,0x1aa6,0x1aa9,0x1aac,0x1aaf,0x1ab2,0x1ab5,0x1ab8,0x1abb,0x1abe,0x1ac1,0x1ac4,0x1ac7,0x1aca,0x1acd,0x1ad0,0x1ad3,0x1ad6,0x1ad9,0x1adc,0x1adf,0x1ae2,0x1ae5,0x1ae8,0x1aeb,0x1aee,0x1af1,0x1af4,0x1af7,0x1afa,0x1afd,0x1b00,0x1b03,0x1b06,0x1b09,0x1b0c,0x1b0f,0x1b12,0x1b15,0x1b18,0x1b1b,0x1b1e,0x1b21,0x1b24,0x1b27,0x1b2a,0x1b2d,0x1b30,0x1b33,0x1b36,0x1b39,0x1b3c,0x1b3f,0x1b42,0x1b45,0x1b48,0x1b4b,0x1b4e,0x1b51,0x1b54,0x1b57,0x1b5a,0x1b5d,0x1b60,0x1b63,0x1b66,0x1b69)
        )
    LIMIT 1001
    I think it's because of the subquery that we run to determine value for HasChildren. However, I think we already have that information available to us from loading the initial view. Maybe we don't need the subquery here, then?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tree widget: Hierarchical categories tree
3 participants