perf(catalog): resolve filename filters once per query, not per row
The 000036 evaluator probes the rules table and runs two regexes for every catalog file row; the first-level page of the 8k-file education source took 2.5-5s per query and the browser hung on 'reading first-level directory'. - source_catalog_nodes gains a STORED generated ext column (000038) - catalog_filter_context() resolves the connection's source-level allow/ exclude sets once; hot queries match node.ext against arrays (000039) - filename_is_filtered stays the exact fallback, used only when the connection has directory-scoped rules - ListCatalogSources, ListCatalogNodes (current/subtree/total/items) and RouteCatalogFiles fan-out adopt the fast path Education root page: 4770ms -> 12ms; all-source counts: 54ms.
This commit is contained in:
@@ -99,7 +99,9 @@ FOR UPDATE OF node`, request.ConnectionID, nodeIDs)
|
||||
}
|
||||
}
|
||||
|
||||
rows, err := tx.Query(ctx, `WITH RECURSIVE selected AS (
|
||||
rows, err := tx.Query(ctx, `WITH RECURSIVE filter_ctx AS MATERIALIZED (
|
||||
SELECT * FROM catalog_filter_context($1)
|
||||
), selected AS (
|
||||
SELECT node.snapshot_id,node.node_id,node.node_type
|
||||
FROM source_catalog_heads head
|
||||
JOIN source_catalog_nodes node ON node.snapshot_id=head.snapshot_id
|
||||
@@ -116,8 +118,11 @@ SELECT DISTINCT node.node_id,node.name,node.relative_path,node.size_bytes,node.m
|
||||
node.source_locator_hash,(node.node_id=ANY($2::text[])) AS directly_selected
|
||||
FROM descendants
|
||||
JOIN source_catalog_nodes node ON node.snapshot_id=descendants.snapshot_id AND node.node_id=descendants.node_id
|
||||
CROSS JOIN filter_ctx ctx
|
||||
WHERE node.node_type='file'
|
||||
AND NOT filename_is_filtered($1,node.relative_path,node.name)
|
||||
AND (node.ext=''
|
||||
OR (ctx.has_dir AND NOT filename_is_filtered($1,node.relative_path,node.name))
|
||||
OR (NOT ctx.has_dir AND (ctx.src_allow IS NULL OR node.ext = ANY(ctx.src_allow)) AND NOT node.ext = ANY(ctx.src_excl)))
|
||||
ORDER BY node.node_id`, request.ConnectionID, nodeIDs)
|
||||
if err != nil {
|
||||
return governance.CatalogRouteResult{}, fmt.Errorf("select catalog route files: %w", err)
|
||||
|
||||
Reference in New Issue
Block a user