feat(ingest): 源与目录文件名过滤及钉钉文档导出
- filename_filter_rules table (000035) with source-root and per-directory rows - additive inheritance: source default + every ancestor directory contributes - filename_is_filtered() SQL predicate applied to catalog browsing, subtree counts, change-set diffing, routing fan-out and artifact fetch manifests - fetch_state 'filtered' (CHECK extended); reconcile cancels/restores fetch jobs, retires planned publications and blocks items when rules change - GET/PUT/DELETE /api/v1/filename-filters (Idempotency-Key, normalized extensions) + Settings and Catalog filter editors - failJobSQL no longer swallows the claimed row when the failure projection upserts (fixes spurious 'lease lost' retries) - DingTalk live fetch: adoc/axls now use the export-job pipeline (HTTP 403 from file/download fixed), header-signature downloads supported
This commit is contained in:
@@ -15,7 +15,11 @@ var ErrCatalogNodeNotFound = errors.New("catalog node not found")
|
||||
func (s *Store) ListCatalogSources(ctx context.Context) ([]governance.CatalogSource, error) {
|
||||
rows, err := s.db.Query(ctx, `
|
||||
SELECT connection.id, connection.source_type, snapshot.source_label, root.node_id,
|
||||
snapshot.folder_count - 1, snapshot.file_count, head.activated_at,
|
||||
snapshot.folder_count - 1,
|
||||
(SELECT COUNT(*)::integer FROM source_catalog_nodes file
|
||||
WHERE file.snapshot_id=snapshot.id AND file.node_type='file'
|
||||
AND NOT filename_is_filtered(connection.id,file.relative_path,file.name)),
|
||||
head.activated_at,
|
||||
'ready', COALESCE(refresh.duration_ms,0)
|
||||
FROM source_catalog_heads head
|
||||
JOIN source_catalog_snapshots snapshot ON snapshot.id=head.snapshot_id AND snapshot.source_connection_id=head.source_connection_id
|
||||
@@ -62,8 +66,19 @@ func (s *Store) ListCatalogNodes(ctx context.Context, filter governance.CatalogN
|
||||
page := governance.CatalogNodePage{Items: []governance.CatalogNode{}, Limit: filter.Limit, Offset: filter.Offset}
|
||||
var parentID *string
|
||||
err := s.db.QueryRow(ctx, `
|
||||
SELECT node.node_id,node.parent_node_id,node.node_type,node.name,node.direct_child_count,
|
||||
node.subtree_file_count,node.subtree_bytes,node.size_bytes,node.modified_at
|
||||
SELECT node.node_id,node.parent_node_id,node.node_type,node.name,
|
||||
(SELECT COUNT(*)::integer FROM source_catalog_nodes child
|
||||
WHERE child.snapshot_id=node.snapshot_id AND child.parent_node_id=node.node_id
|
||||
AND (child.node_type='folder' OR NOT filename_is_filtered($1,child.relative_path,child.name))),
|
||||
(SELECT COUNT(*)::integer FROM source_catalog_nodes file
|
||||
WHERE file.snapshot_id=node.snapshot_id AND file.node_type='file'
|
||||
AND (node.relative_path='' OR file.relative_path LIKE node.relative_path||'/%')
|
||||
AND NOT filename_is_filtered($1,file.relative_path,file.name)),
|
||||
(SELECT COALESCE(SUM(COALESCE(file.size_bytes,0)),0)::bigint FROM source_catalog_nodes file
|
||||
WHERE file.snapshot_id=node.snapshot_id AND file.node_type='file'
|
||||
AND (node.relative_path='' OR file.relative_path LIKE node.relative_path||'/%')
|
||||
AND NOT filename_is_filtered($1,file.relative_path,file.name)),
|
||||
node.size_bytes,node.modified_at
|
||||
FROM source_catalog_heads head
|
||||
JOIN source_catalog_nodes node ON node.snapshot_id=head.snapshot_id
|
||||
WHERE head.source_connection_id=$1 AND node.node_id=$2 AND node.node_type='folder'`, filter.ConnectionID, filter.ParentNodeID).Scan(
|
||||
@@ -112,7 +127,8 @@ SELECT node_id,name FROM trail ORDER BY depth DESC`, filter.ConnectionID, filter
|
||||
if err := s.db.QueryRow(ctx, `
|
||||
SELECT COUNT(*)::integer FROM source_catalog_heads head
|
||||
JOIN source_catalog_nodes node ON node.snapshot_id=head.snapshot_id
|
||||
WHERE head.source_connection_id=$1 AND node.parent_node_id=$2`, filter.ConnectionID, filter.ParentNodeID).Scan(&page.Total); err != nil {
|
||||
WHERE head.source_connection_id=$1 AND node.parent_node_id=$2
|
||||
AND (node.node_type='folder' OR NOT filename_is_filtered($1,node.relative_path,node.name))`, filter.ConnectionID, filter.ParentNodeID).Scan(&page.Total); err != nil {
|
||||
return governance.CatalogNodePage{}, fmt.Errorf("count catalog nodes: %w", err)
|
||||
}
|
||||
|
||||
@@ -122,6 +138,7 @@ WITH RECURSIVE current_head AS (
|
||||
), selected AS MATERIALIZED (
|
||||
SELECT node.* FROM current_head head JOIN source_catalog_nodes node ON node.snapshot_id=head.snapshot_id
|
||||
WHERE node.parent_node_id=$2
|
||||
AND (node.node_type='folder' OR NOT filename_is_filtered($1,node.relative_path,node.name))
|
||||
ORDER BY CASE node.node_type WHEN 'folder' THEN 0 ELSE 1 END,node.sort_order,lower(node.name),node.node_id
|
||||
LIMIT $3 OFFSET $4
|
||||
), descendants(ancestor_id,snapshot_id,node_id) AS (
|
||||
@@ -135,9 +152,10 @@ WITH RECURSIVE current_head AS (
|
||||
COALESCE(item_scope.visibility,directory_scope.visibility,item.visibility) AS effective_visibility,
|
||||
publication.id AS publication_id,publication.ingest_state,publication.processing_state,
|
||||
current_version.content_state AS version_content_state,content.content_state AS object_content_state,
|
||||
content.local_spool_ref
|
||||
content.local_spool_ref,leaf.size_bytes
|
||||
FROM descendants
|
||||
JOIN source_catalog_nodes leaf ON leaf.snapshot_id=descendants.snapshot_id AND leaf.node_id=descendants.node_id AND leaf.node_type='file'
|
||||
AND NOT filename_is_filtered($1,leaf.relative_path,leaf.name)
|
||||
LEFT JOIN source_items item ON item.id=leaf.source_item_id
|
||||
LEFT JOIN source_item_versions current_version ON current_version.source_item_id=item.id AND current_version.revision=item.revision
|
||||
LEFT JOIN content_objects content ON content.id=current_version.content_object_id
|
||||
@@ -158,6 +176,8 @@ WITH RECURSIVE current_head AS (
|
||||
) publication ON TRUE
|
||||
), stats AS (
|
||||
SELECT ancestor_id,
|
||||
COUNT(*)::integer AS eligible_file_count,
|
||||
COALESCE(SUM(COALESCE(size_bytes,0)),0)::bigint AS eligible_bytes,
|
||||
COUNT(DISTINCT source_item_id) FILTER (WHERE publication_id IS NOT NULL)::integer AS imported_count,
|
||||
COUNT(DISTINCT source_item_id) FILTER (WHERE publication_id IS NOT NULL AND processing_state='completed')::integer AS parsed_count,
|
||||
COUNT(DISTINCT source_item_id) FILTER (WHERE publication_id IS NOT NULL AND (ingest_state='uploading' OR processing_state IN ('processing','finalizing')))::integer AS active_count,
|
||||
@@ -169,7 +189,12 @@ WITH RECURSIVE current_head AS (
|
||||
FROM file_state GROUP BY ancestor_id
|
||||
)
|
||||
SELECT selected.node_id,selected.parent_node_id,selected.node_type,selected.name,
|
||||
selected.direct_child_count,selected.subtree_file_count,selected.subtree_bytes,
|
||||
CASE WHEN selected.node_type='file' THEN 0 ELSE (
|
||||
SELECT COUNT(*)::integer FROM source_catalog_nodes child
|
||||
WHERE child.snapshot_id=selected.snapshot_id AND child.parent_node_id=selected.node_id
|
||||
AND (child.node_type='folder' OR NOT filename_is_filtered($1,child.relative_path,child.name))
|
||||
) END,
|
||||
COALESCE(stats.eligible_file_count,0),COALESCE(stats.eligible_bytes,0),
|
||||
selected.size_bytes,selected.modified_at,selected.content_sha256,COALESCE(stats.visibility,'unknown'),
|
||||
COALESCE(stats.imported_count,0),COALESCE(stats.parsed_count,0),
|
||||
COALESCE(stats.active_count,0),COALESCE(stats.failed_count,0),COALESCE(stats.routable_count,0)
|
||||
|
||||
Reference in New Issue
Block a user