MCPcopy
hub / github.com/tirth8205/code-review-graph / upsert_edge

Method upsert_edge

code_review_graph/graph.py:223–255  ·  view source on GitHub ↗

Insert or update an edge.

(self, edge: EdgeInfo)

Source from the content-addressed store, hash-verified

221 return row["id"]
222
223 def upsert_edge(self, edge: EdgeInfo) -> int:
224 """Insert or update an edge."""
225 now = time.time()
226 extra_dict = edge.extra if edge.extra else {}
227 confidence = float(extra_dict.get("confidence", 1.0))
228 confidence_tier = str(extra_dict.get("confidence_tier", "EXTRACTED"))
229 extra = json.dumps(extra_dict)
230
231 # Check for existing edge (include line so multiple call sites are preserved)
232 existing = self._conn.execute(
233 """SELECT id FROM edges
234 WHERE kind=? AND source_qualified=? AND target_qualified=?
235 AND file_path=? AND line=?""",
236 (edge.kind, edge.source, edge.target, edge.file_path, edge.line),
237 ).fetchone()
238
239 if existing:
240 self._conn.execute(
241 "UPDATE edges SET line=?, extra=?, confidence=?, confidence_tier=?,"
242 " updated_at=? WHERE id=?",
243 (edge.line, extra, confidence, confidence_tier, now, existing["id"]),
244 )
245 return existing["id"]
246
247 self._conn.execute(
248 """INSERT INTO edges
249 (kind, source_qualified, target_qualified, file_path, line, extra,
250 confidence, confidence_tier, updated_at)
251 VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)""",
252 (edge.kind, edge.source, edge.target, edge.file_path, edge.line, extra,
253 confidence, confidence_tier, now),
254 )
255 return self._conn.execute("SELECT last_insert_rowid()").fetchone()[0]
256
257 def remove_file_data(self, file_path: str) -> None:
258 """Remove all nodes and edges associated with a file."""

Callers 15

_make_chain_storeMethod · 0.95
store_with_dataFunction · 0.95
large_storeFunction · 0.95
store_file_batchMethod · 0.95
_seed_realistic_graphMethod · 0.80
_seed_dataMethod · 0.80
_seed_dataMethod · 0.80

Calls 1

getMethod · 0.80

Tested by 15

_make_chain_storeMethod · 0.76
store_with_dataFunction · 0.76
large_storeFunction · 0.76
_seed_realistic_graphMethod · 0.64
_seed_dataMethod · 0.64
_seed_dataMethod · 0.64
_seed_dataMethod · 0.64
_seed_dataMethod · 0.64