Back to the room

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

Code Observatory / method

index

codeintel.indexer.CodeIndexer.index

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 (9)
SymbolFileResolved by
open_checkoutgit_source.pythrough an import
_utcnowindexer.pysame file
_count_chunksindexer.pysame file
_count_linesindexer.pysame file
_rebuild_graphindexer.pysame file
_syncindexer.pysame file
get_or_create_repositoryindexer.pysame file
IndexStatsindexer.pysame file
as_dictindexer.pysame file
Inside (1)
SymbolFileResolved by
CodeIndexerindexer.pysame file
codeintel.indexer.CodeIndexer.indexbackend/app/codeintel/indexer.py, lines 185–241Open source
    def index(self, ref: RepoRef, branch: str | None = None, *, force: bool = False) -> IndexStats:        stats = IndexStats(repository=ref.canonical_url)        stats.embedding_model = self.embedder.model_id if self.embedder else None        t0 = time.monotonic()        repo = self.get_or_create_repository(ref, branch)        repo_id = repo.id        previous_commit = repo.last_commit_sha        previous_model = (repo.stats or {}).get("embedding_model")        repo.index_status = "indexing"        self.db.commit()        try:            t = time.monotonic()            checkout = open_checkout(ref, branch=branch, token=self.clone_token, timeout=self.clone_timeout)            stats.timings_s["checkout"] += time.monotonic() - t            with checkout:                stats.commit_sha = checkout.commit                model_changed = previous_model != stats.embedding_model                if (                    not force                    and previous_commit == checkout.commit                    and not model_changed                    and (repo.stats or {}).get("outcome") is not None                ):                    stats.outcome = "unchanged"                    stats.chunks_total = self._count_chunks(repo_id)                    repo = self.db.get(Repository, repo_id)                    repo.index_status = "ready"                    self.db.commit()                    stats.timings_s["total"] = time.monotonic() - t0                    return stats                self._sync(repo_id, ref, checkout, stats, rewrite_all=force or model_changed)            t = time.monotonic()            self._rebuild_graph(repo_id, stats)            stats.timings_s["graph"] += time.monotonic() - t            stats.outcome = "indexed"            stats.chunks_total = self._count_chunks(repo_id)            stats.timings_s["total"] = time.monotonic() - t0            repo = self.db.get(Repository, repo_id)            repo.last_commit_sha = stats.commit_sha            repo.last_indexed_at = _utcnow()            repo.index_status = "ready"            repo.total_files = stats.files_indexed + stats.files_unchanged            repo.total_lines = self._count_lines(repo_id)            repo.stats = stats.as_dict()            self.db.commit()            return stats        except Exception:            self.db.rollback()            repo = self.db.get(Repository, repo_id)            if repo is not None:                # Keep last_commit_sha: the previous index stays searchable.                repo.index_status = "failed"                self.db.commit()            raise

What the index recorded

Signature
def index(self, ref: RepoRef, branch: str | None, *, force: bool) -> IndexStats:
File
backend/app/codeintel/indexer.py
Lines
185–241
Parser
python-ast
Git blob
e8fdfa7b5545e821f7649d68cfadd2aae85b89d0
Call sites
13 named, 10 resolved, 3 left unlinked
Outside this subset
1 more edges reach code outside the graph shown here

Read it on GitHub at this commit