* 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)
| 2809 | * without changing the target/kind index's established kind precedence. |
| 2810 | */ |
| 2811 | getIncomingEdges(targetId: string, kinds?: EdgeKind[], limit?: number): Edge[] { |
| 2812 | if ((kinds && kinds.length > 0) || limit !== undefined) { |
| 2813 | let sql = 'SELECT * FROM edges WHERE target = ?'; |
| 2814 | const params: (string | number)[] = [targetId]; |
| 2815 | if (kinds && kinds.length > 0) { |
| 2816 | sql += ` AND kind IN (${kinds.map(() => '?').join(',')})`; |
| 2817 | params.push(...kinds); |
| 2818 | } |
| 2819 | sql += ' ORDER BY kind, source, line, col'; |
| 2820 | if (limit !== undefined) { |
| 2821 | sql += ' LIMIT ?'; |
| 2822 | params.push(Math.max(0, Math.floor(limit))); |
| 2823 | } |
| 2824 | const rows = this.edgeKindStmt(sql).all(...params) as EdgeRow[]; |
| 2825 | return rows.map(rowToEdge); |
| 2826 | } |
| 2827 | |
| 2828 | if (!this.stmts.getEdgesByTarget) { |
| 2829 | this.stmts.getEdgesByTarget = this.db.prepare('SELECT * FROM edges WHERE target = ? ORDER BY kind, source, line, col'); |
| 2830 | } |
| 2831 | const rows = this.stmts.getEdgesByTarget.all(targetId) as EdgeRow[]; |
| 2832 | return rows.map(rowToEdge); |
| 2833 | } |
| 2834 | |
| 2835 | /** |
| 2836 | * Outgoing edges for MANY source nodes in one query. |