Transport import: case-insensitive name collision in ApplyTemplatesAsync dictionary; preview N+1; stale flattener doc #93

Closed
opened 2026-11-09 13:32:52 -05:00 by dohertj2 · 1 comment
Owner

Found during #47 (transport import performance):

  • ApplyTemplatesAsync builds a dictionary from a by-name DB query. Under SQL Server's case-insensitive collation two templates whose names differ only in case would make that dictionary throw. Untested — check whether template names are already unique case-insensitively (constraint/validation); if not, add a test and a case-insensitive comparer.
  • Preview still looks up database connections, notification lists and API methods one name at a time (small N+1); left because in-memory matching could differ from SQL Server collation. Batch with a collation-equivalent comparer.
  • Component-TemplateEngine.md says the flattener reads GetAllTemplatesAsync; no such call found in the Flattening code — verify and fix the doc.
Found during #47 (transport import performance): - `ApplyTemplatesAsync` builds a dictionary from a by-name DB query. Under SQL Server's case-insensitive collation two templates whose names differ only in case would make that dictionary throw. Untested — check whether template names are already unique case-insensitively (constraint/validation); if not, add a test and a case-insensitive comparer. - Preview still looks up database connections, notification lists and API methods one name at a time (small N+1); left because in-memory matching could differ from SQL Server collation. Batch with a collation-equivalent comparer. - `Component-TemplateEngine.md` says the flattener reads GetAllTemplatesAsync; no such call found in the Flattening code — verify and fix the doc.
dohertj2 added the type:followuppriority:p3 labels 2026-11-09 13:32:52 -05:00
Author
Owner

Fixed on main c7d868c5: (a) base templates are already unique case-insensitively (filtered unique index on Template.Name where IsDerived=0, CI collation), but derived templates aren't covered, and the old ordinal dictionaries also missed 'PUMP' vs 'Pump'. ApplyTemplatesAsync and preview now use a non-throwing case-insensitive lookup, base wins over derived. (b) preview reads database connections / notification lists / API methods once via GetAll*Async and matches case-insensitively (apply-side lookups unchanged). (c) Component-TemplateEngine.md corrected — the flattener loads chains via GetTemplateWithChildrenAsync memoised per FlattenSession, never GetAllTemplatesAsync. Tests: ImportNameLookupTests (call-counting proxy: 0 by-name queries, 1 GetAll per library, differently-cased target names not reported New; duplicate case variants; base-over-derived) — all 3 fail with the old lookup. Transport 198, Transport.IntegrationTests 141 passed; slnx 0 warnings.

Fixed on main c7d868c5: (a) base templates are already unique case-insensitively (filtered unique index on Template.Name where IsDerived=0, CI collation), but derived templates aren't covered, and the old ordinal dictionaries also missed 'PUMP' vs 'Pump'. ApplyTemplatesAsync and preview now use a non-throwing case-insensitive lookup, base wins over derived. (b) preview reads database connections / notification lists / API methods once via GetAll*Async and matches case-insensitively (apply-side lookups unchanged). (c) Component-TemplateEngine.md corrected — the flattener loads chains via GetTemplateWithChildrenAsync memoised per FlattenSession, never GetAllTemplatesAsync. Tests: ImportNameLookupTests (call-counting proxy: 0 by-name queries, 1 GetAll per library, differently-cased target names not reported New; duplicate case variants; base-over-derived) — all 3 fail with the old lookup. Transport 198, Transport.IntegrationTests 141 passed; slnx 0 warnings.
Sign in to join this conversation.