Back to the room

Pass 3 of 3 · Deep dive of PHAROSPass 1 · OverviewPass 2 · How it works

Code Observatory / method

_rebuild_graph

codeintel.indexer.CodeIndexer._rebuild_graph

PINNED SOURCE Source and edges from the index at this commit. An execution appears only where one was recorded.

PHAROS at 975a38dMIT license

Around this symbol

Search all symbols

Loading

Calls (3)
SymbolFileResolved by
build_edgesgraph.pythrough an import
ChunkNodegraph.pythrough an import
as_dictindexer.pysame file
Called by (1)
SymbolFileResolved by
indexindexer.pysame file
Inside (1)
SymbolFileResolved by
CodeIndexerindexer.pysame file
codeintel.indexer.CodeIndexer._rebuild_graphbackend/app/codeintel/indexer.py, lines 499–545Open source
    def _rebuild_graph(self, repo_id, stats: IndexStats) -> None:        rows = self.db.execute(            select(                DocumentChunk.id,                DocumentChunk.language,                DocumentChunk.ast_node_type,                DocumentChunk.symbol_name,                DocumentChunk.chunk_metadata,            ).where(DocumentChunk.repository_id == repo_id)        ).all()        nodes = []        for cid, language, kind, qual, meta in rows:            meta = meta or {}            nodes.append(                ChunkNode(                    id=str(cid),                    path=meta.get("path", ""),                    language=language or "",                    kind=kind or "",                    name=meta.get("name") or (qual or "").rsplit(".", 1)[-1],                    qualified_name=qual or "",                    parent=meta.get("parent"),                    calls=meta.get("calls") or [],                    imports=meta.get("imports") or [],                    import_map=meta.get("import_map") or {},                )            )        edges, gstats = build_edges(nodes)        self.db.execute(delete(CodeEdge).where(CodeEdge.repository_id == repo_id))        import uuid as _uuid        rows_to_insert = [            {                "id": _uuid.uuid4(),                "repository_id": repo_id,                "source_chunk_id": _uuid.UUID(e.source_id),                "target_chunk_id": _uuid.UUID(e.target_id),                "target_name": e.target_name[:512],                "edge_type": e.edge_type,                "resolution": e.resolution,            }            for e in edges        ]        for i in range(0, len(rows_to_insert), 1000):            self.db.execute(CodeEdge.__table__.insert(), rows_to_insert[i : i + 1000])        self.db.commit()        stats.graph = {"edges": len(edges), **gstats.as_dict()}

What the index recorded

Signature
def _rebuild_graph(self, repo_id, stats: IndexStats) -> None:
File
backend/app/codeintel/indexer.py
Lines
499–545
Parser
python-ast
Git blob
e8fdfa7b5545e821f7649d68cfadd2aae85b89d0
Call sites
18 named, 6 resolved, 12 left unlinked
Outside this subset
3 more edges reach code outside the graph shown here

Read it on GitHub at this commit