* Get incoming edges to a node. Kind must precede opaque source IDs: * file IDs sort before function IDs, so source-first ordering lets imports * displace actual calls in capped caller lists. Keep deterministic ties * without changing the target/kind index's established kind precedence.
(targetId: string, kinds?: EdgeKind[], limit?: number)
| 2775 | * without changing the target/kind index's established kind precedence. |
| 2776 | */ |
| 2777 | getIncomingEdges(targetId: string, kinds?: EdgeKind[], limit?: number): Edge[] { |
| 2778 | if ((kinds && kinds.length > 0) || limit !== undefined) { |
| 2779 | let sql = 'SELECT * FROM edges WHERE target = ?'; |
| 2780 | const params: (string | number)[] = [targetId]; |
| 2781 | if (kinds && kinds.length > 0) { |
| 2782 | sql += ` AND kind IN (${kinds.map(() => '?').join(',')})`; |
| 2783 | params.push(...kinds); |
| 2784 | } |
| 2785 | sql += ' ORDER BY kind, source, line, col'; |
| 2786 | if (limit !== undefined) { |
| 2787 | sql += ' LIMIT ?'; |
| 2788 | params.push(Math.max(0, Math.floor(limit))); |
| 2789 | } |
| 2790 | const rows = this.edgeKindStmt(sql).all(...params) as EdgeRow[]; |
| 2791 | return rows.map(rowToEdge); |
| 2792 | } |
| 2793 | |
| 2794 | if (!this.stmts.getEdgesByTarget) { |
| 2795 | this.stmts.getEdgesByTarget = this.db.prepare('SELECT * FROM edges WHERE target = ? ORDER BY kind, source, line, col'); |
| 2796 | } |
| 2797 | const rows = this.stmts.getEdgesByTarget.all(targetId) as EdgeRow[]; |
| 2798 | return rows.map(rowToEdge); |
| 2799 | } |
| 2800 | |
| 2801 | /** |
| 2802 | * Outgoing edges for MANY source nodes in one query. |