mirror of
https://github.com/tiennm99/goclaw.git
synced 2026-10-13 18:15:34 +00:00
fix(kg): merge recursive CTE branches and widen detail dialog
Combine forward+reverse traversal into single recursive branch using CASE to fix SQLSTATE 42P19 (PostgreSQL parses triple UNION ALL as left-associative, putting recursive ref in non-recursive term). Also widen entity detail dialog from max-w-5xl to max-w-7xl.
This commit is contained in:
1 parent
1d39626a88
commit
ef0de0d760
2 files changed
+13
-39
No files matched your search
@@ -62,28 +62,15 @@ func (s *PGKnowledgeGraphStore) Traverse(ctx context.Context, agentID, userID, s
|
||||
e.created_at, e.updated_at,
|
||||
p.depth + 1,
|
||||
p.path || e.id::text,
|
||||
r.relation_type
|
||||
CASE WHEN r.source_entity_id = p.id
|
||||
THEN r.relation_type
|
||||
ELSE '~' || r.relation_type
|
||||
END
|
||||
FROM paths p
|
||||
JOIN kg_relations r ON p.id = r.source_entity_id AND r.agent_id = $2
|
||||
JOIN kg_entities e ON r.target_entity_id = e.id AND e.agent_id = $2
|
||||
JOIN kg_relations r ON (r.source_entity_id = p.id OR r.target_entity_id = p.id) AND r.agent_id = $2
|
||||
JOIN kg_entities e ON e.id = (CASE WHEN r.source_entity_id = p.id THEN r.target_entity_id ELSE r.source_entity_id END) AND e.agent_id = $2
|
||||
WHERE p.depth < $%d
|
||||
AND NOT e.id::text = ANY(p.path)
|
||||
|
||||
UNION ALL
|
||||
|
||||
SELECT
|
||||
e.id, e.agent_id, e.user_id, e.external_id,
|
||||
e.name, e.entity_type, e.description,
|
||||
e.properties, e.source_id, e.confidence,
|
||||
e.created_at, e.updated_at,
|
||||
p.depth + 1,
|
||||
p.path || e.id::text,
|
||||
'~' || r.relation_type
|
||||
FROM paths p
|
||||
JOIN kg_relations r ON p.id = r.target_entity_id AND r.agent_id = $2
|
||||
JOIN kg_entities e ON r.source_entity_id = e.id AND e.agent_id = $2
|
||||
WHERE p.depth < $%[2]d
|
||||
AND NOT e.id::text = ANY(p.path)
|
||||
)
|
||||
SELECT
|
||||
id, agent_id, user_id, external_id,
|
||||
@@ -123,28 +110,15 @@ func (s *PGKnowledgeGraphStore) Traverse(ctx context.Context, agentID, userID, s
|
||||
e.created_at, e.updated_at,
|
||||
p.depth + 1,
|
||||
p.path || e.id::text,
|
||||
r.relation_type
|
||||
CASE WHEN r.source_entity_id = p.id
|
||||
THEN r.relation_type
|
||||
ELSE '~' || r.relation_type
|
||||
END
|
||||
FROM paths p
|
||||
JOIN kg_relations r ON p.id = r.source_entity_id AND r.user_id = $3
|
||||
JOIN kg_entities e ON r.target_entity_id = e.id AND e.user_id = $3
|
||||
JOIN kg_relations r ON (r.source_entity_id = p.id OR r.target_entity_id = p.id) AND r.user_id = $3
|
||||
JOIN kg_entities e ON e.id = (CASE WHEN r.source_entity_id = p.id THEN r.target_entity_id ELSE r.source_entity_id END) AND e.user_id = $3
|
||||
WHERE p.depth < $%d
|
||||
AND NOT e.id::text = ANY(p.path)
|
||||
|
||||
UNION ALL
|
||||
|
||||
SELECT
|
||||
e.id, e.agent_id, e.user_id, e.external_id,
|
||||
e.name, e.entity_type, e.description,
|
||||
e.properties, e.source_id, e.confidence,
|
||||
e.created_at, e.updated_at,
|
||||
p.depth + 1,
|
||||
p.path || e.id::text,
|
||||
'~' || r.relation_type
|
||||
FROM paths p
|
||||
JOIN kg_relations r ON p.id = r.target_entity_id AND r.user_id = $3
|
||||
JOIN kg_entities e ON r.source_entity_id = e.id AND e.user_id = $3
|
||||
WHERE p.depth < $%[2]d
|
||||
AND NOT e.id::text = ANY(p.path)
|
||||
)
|
||||
SELECT
|
||||
id, agent_id, user_id, external_id,
|
||||
|
||||
@@ -84,7 +84,7 @@ export function KGEntityDetailDialog({ open, onOpenChange, agentId, entity, getE
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={(v) => !traversing && onOpenChange(v)}>
|
||||
<DialogContent aria-describedby={undefined} className="max-w-5xl max-h-[90vh] flex flex-col">
|
||||
<DialogContent aria-describedby={undefined} className="max-w-7xl max-h-[90vh] flex flex-col">
|
||||
<DialogHeader>
|
||||
<DialogTitle className="flex items-center gap-2">
|
||||
<span>{entity?.name}</span>
|
||||
|
||||
Reference in new issue
Block a user