Skip to content

armgit / Ix

Public Imported from GitHub
0

Understand any codebase instantly. System intelligence for codebases, built for humans and AI.

perf: skip source-hash lookup on first ingest

Tanner Kocherf3020dff8458
diff --git a/ix-cli/src/cli/commands/ingest.ts b/ix-cli/src/cli/commands/ingest.ts
index add5559a..6c2ca809 100644
--- a/ix-cli/src/cli/commands/ingest.ts
+++ b/ix-cli/src/cli/commands/ingest.ts
@@ -143,8 +143,22 @@ export async function ingestFiles(
const discovered = performance.now();
timings.discoverMs = Math.round(discovered - start);
- // Phase: hash lookup
- const knownHashes = opts.force ? new Map<string, string>() : await loadExistingHashes(client, filePaths, debug);
+ // Phase: hash lookup (skipped on first ingest when no baseline exists)
+ let knownHashes: Map<string, string>;
+ let baselineSkipped = false;
+ if (opts.force) {
+ knownHashes = new Map();
+ } else {
+ const hasBaseline = await checkIngestBaseline(client, debug);
+ if (hasBaseline) {
+ if (debug) process.stderr.write('\n Existing ingest baseline found — performing source hash comparison\n');
+ knownHashes = await loadExistingHashes(client, filePaths, debug);
+ } else {
+ if (debug) process.stderr.write('\n No existing ingest baseline found — skipping source hash lookup\n');
+ knownHashes = new Map();
+ baselineSkipped = true;
+ }
+ }
const hashed = performance.now();
timings.hashMs = Math.round(hashed - discovered);
@@ -302,6 +316,15 @@ export async function ingestFiles(
// Load existing hashes from the server for change detection
// ---------------------------------------------------------------------------
+async function checkIngestBaseline(client: IxClient, debug = false): Promise<boolean> {
+ try {
+ return await client.hasIngestBaseline();
+ } catch (err) {
+ if (debug) process.stderr.write(`\n [baseline check failed, falling back to full hash lookup] ${err}\n`);
+ return true; // Safe fallback: assume baseline exists, do the full lookup
+ }
+}
+
async function loadExistingHashes(client: IxClient, filePaths: string[], debug = false): Promise<Map<string, string>> {
try {
return await client.getSourceHashes(filePaths);
diff --git a/ix-cli/src/client/api.ts b/ix-cli/src/client/api.ts
index 49a09c88..eea5dd5a 100644
--- a/ix-cli/src/client/api.ts
+++ b/ix-cli/src/client/api.ts
@@ -174,6 +174,11 @@ export class IxClient {
return this.post("/v1/patch", patch);
}
+ async hasIngestBaseline(): Promise<boolean> {
+ const result = await this.get<{ exists: boolean }>('/v1/source-hashes/exists');
+ return result.exists;
+ }
+
async getSourceHashes(filePaths: string[]): Promise<Map<string, string>> {
const result = await this.post<Record<string, string>>('/v1/source-hashes', { uris: filePaths });
return new Map(Object.entries(result));
diff --git a/memory-layer/src/main/scala/ix/memory/api/SourceHashRoutes.scala b/memory-layer/src/main/scala/ix/memory/api/SourceHashRoutes.scala
index dd5e8ea5..dda453c0 100644
--- a/memory-layer/src/main/scala/ix/memory/api/SourceHashRoutes.scala
+++ b/memory-layer/src/main/scala/ix/memory/api/SourceHashRoutes.scala
@@ -22,5 +22,11 @@ class SourceHashRoutes(queryApi: GraphQueryApi) {
hashes <- queryApi.getSourceHashes(body.uris)
resp <- Ok(Json.fromFields(hashes.map { case (k, v) => k -> v.asJson }))
} yield resp).handleErrorWith(ErrorHandler.handle(_))
+
+ case GET -> Root / "v1" / "source-hashes" / "exists" =>
+ (for {
+ exists <- queryApi.hasIngestBaseline()
+ resp <- Ok(Json.obj("exists" -> exists.asJson))
+ } yield resp).handleErrorWith(ErrorHandler.handle(_))
}
}
diff --git a/memory-layer/src/main/scala/ix/memory/db/ArangoGraphQueryApi.scala b/memory-layer/src/main/scala/ix/memory/db/ArangoGraphQueryApi.scala
index 4e641545..4a31b3e3 100644
--- a/memory-layer/src/main/scala/ix/memory/db/ArangoGraphQueryApi.scala
+++ b/memory-layer/src/main/scala/ix/memory/db/ArangoGraphQueryApi.scala
@@ -448,6 +448,15 @@ class ArangoGraphQueryApi(client: ArangoClient) extends GraphQueryApi {
}
}
+ override def hasIngestBaseline(): IO[Boolean] =
+ client.query(
+ """FOR p IN patches
+ | FILTER p.data.source.sourceHash != null
+ | LIMIT 1
+ | RETURN 1""".stripMargin,
+ Map.empty
+ ).map(_.nonEmpty)
+
override def expandByName(
name: String,
direction: Direction,
diff --git a/memory-layer/src/main/scala/ix/memory/db/GraphQueryApi.scala b/memory-layer/src/main/scala/ix/memory/db/GraphQueryApi.scala
index c5f1b84e..a3e20915 100644
--- a/memory-layer/src/main/scala/ix/memory/db/GraphQueryApi.scala
+++ b/memory-layer/src/main/scala/ix/memory/db/GraphQueryApi.scala
@@ -24,6 +24,7 @@ trait GraphQueryApi {
def getDiffSummary(fromRev: Rev, toRev: Rev): IO[Map[String, Int]]
def resolvePrefix(prefix: String): IO[Vector[NodeId]]
def getSourceHashes(sourceUris: Seq[String]): IO[Map[String, String]]
+ def hasIngestBaseline(): IO[Boolean]
def expandByName(
name: String,
direction: Direction,