Skip to content

armgit / Ix

Public Imported from GitHub
0

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

revert: remove memory-layer changes, keeping branch parsing-only

Joseph Mikhailb60230812a18
diff --git a/memory-layer/src/main/scala/ix/memory/db/BulkWriteApi.scala b/memory-layer/src/main/scala/ix/memory/db/BulkWriteApi.scala
index 9c213812..d0c51ae0 100644
--- a/memory-layer/src/main/scala/ix/memory/db/BulkWriteApi.scala
+++ b/memory-layer/src/main/scala/ix/memory/db/BulkWriteApi.scala
@@ -44,18 +44,7 @@ class BulkWriteApi(client: ArangoClient) {
Option(doc.get("logical_id")).map(_.toString)
}
- // Collect source URIs so we can tombstone ALL old nodes for each file.
- // This is needed when a re-ingest changes an entity's qualified key (e.g.
- // a method gains a container, shifting its nodeId). Tombstoning only by
- // logical_id would leave the old orphaned entity alive.
- // Include both slash variants so that nodes stored with backslash paths
- // (Windows) are also matched when re-ingesting with forward-slash paths.
- val sourceUris = fileBatches.map(_.filePath).distinct.flatMap { p =>
- Seq(p, p.replace('\\', '/'), p.replace('/', '\\'))
- }.distinct
-
for {
- _ <- tombstoneNodesBySourceUri(sourceUris, newRev)
_ <- tombstoneExistingNodes(logicalIds, newRev)
_ <- retireOldClaims(fileBatches, newRev)
_ <- withRetry(client.bulkInsert("nodes", allNodes))
@@ -66,30 +55,6 @@ class BulkWriteApi(client: ArangoClient) {
} yield CommitResult(Rev(newRev), CommitStatus.Ok)
}
- /** Tombstone every live node whose provenance.source_uri matches one of the given paths.
- * Called before inserting new nodes so that stale entities (whose nodeId changed because
- * they gained or lost a container) are cleaned up even though they share no logical_id
- * with the incoming replacements.
- */
- private def tombstoneNodesBySourceUri(sourceUris: Vector[String], newRev: Long): IO[Unit] = {
- if (sourceUris.isEmpty) IO.unit
- else {
- val uriList = new java.util.ArrayList[String](sourceUris.size)
- sourceUris.foreach(uriList.add)
- client.execute(
- """FOR n IN nodes
- | FILTER n.provenance.source_uri IN @uris
- | AND n.deleted_rev == null
- | UPDATE n WITH { deleted_rev: @rev, updated_at: @now } IN nodes""".stripMargin,
- Map(
- "uris" -> uriList.asInstanceOf[AnyRef],
- "rev" -> Long.box(newRev).asInstanceOf[AnyRef],
- "now" -> Instant.now().toString.asInstanceOf[AnyRef]
- )
- )
- }
- }
-
private def tombstoneExistingNodes(logicalIds: Vector[String], newRev: Long): IO[Unit] = {
if (logicalIds.isEmpty) IO.unit
else {
diff --git a/memory-layer/src/main/scala/ix/memory/map/MapService.scala b/memory-layer/src/main/scala/ix/memory/map/MapService.scala
index 09bec74d..f1c5c96a 100644
--- a/memory-layer/src/main/scala/ix/memory/map/MapService.scala
+++ b/memory-layer/src/main/scala/ix/memory/map/MapService.scala
@@ -283,56 +283,17 @@ class MapService(
val mySegs = dirSegs(myPaths)
val otherSegs = dirSegs(otherPaths)
- val minExclCoverage = math.max(2, r.memberFiles.size * 0.20).toInt
- val exclusive = (mySegs -- otherSegs)
- .filterNot(LabelNoiseTokens.contains)
- // Only use a segment as a discriminator if it covers ≥20% of the cluster's files.
- // This prevents a low-frequency deep segment (e.g. "dummy" in 7/45 files) from
- // winning over segments that actually characterise the majority of the cluster.
- .filter { seg =>
- myPaths.count(p =>
- p.split("[/\\\\]").dropRight(1).exists(_.equalsIgnoreCase(seg))
- ) >= minExclCoverage
+ val exclusive = (mySegs -- otherSegs).filterNot(LabelNoiseTokens.contains)
+
+ // Prefer shorter tokens (more likely to be a meaningful module name).
+ // Fallback: rank by size — largest keeps the clean label, smaller ones get "(2)", "(3)", etc.
+ val suffix = exclusive.toVector.sortBy(s => (s.length, s)).headOption
+ .map(s => s" / ${s.capitalize}")
+ .getOrElse {
+ val rank = group.sortBy(-_.memberFiles.size).indexWhere(_.id == r.id) + 1
+ if (rank <= 1) "" else s" ($rank)"
}
-
- // Prefer shorter tokens (more likely to be a meaningful module name)
- exclusive.toVector.sortBy(s => (s.length, s)).headOption match {
- case Some(seg) =>
- r.copy(label = r.label + s" / ${seg.capitalize}")
- case None =>
- // No exclusive directory found (cross-cutting clusters in the same label group
- // have already claimed all of our directory segments).
- // Fall back to the dominant directory within THIS cluster as a full label
- // replacement — not a suffix — so we don't collide with the parent system name.
- // Strip the common absolute prefix and apply depth weighting (same as inferLabel
- // Strategy 2) so that deeper, more specific directory segments score higher.
- val strippedPaths = myPaths.toSeq.map { p =>
- val segs = p.split("[/\\\\]")
- if (commonPfxLen > 0 && commonPfxLen < segs.length) segs.drop(commonPfxLen)
- else segs
- }
- val dirsWithDepth: Seq[(Int, String)] = strippedPaths.flatMap { segs =>
- segs.dropRight(1).zipWithIndex
- .filterNot { case (s, _) => LabelNoiseTokens.contains(s.toLowerCase) || s.isEmpty }
- .map { case (s, i) => (i, s) }
- }
- val maxD = dirsWithDepth.map(_._1).maxOption.getOrElse(1).toDouble.max(1.0)
- val candidateSegments = dirsWithDepth.groupBy(_._2)
- // Skip the base label itself — we need what distinguishes this cluster *within*
- // the label group, not the project/package name that all siblings share.
- .filterNot { case (seg, _) => seg.equalsIgnoreCase(r.label) }
-
- // Score all candidate segments by frequency × depth-weight.
- // No coverage floor here — depth-weighting already favours specific segments,
- // and imposing a 20% minimum causes large spread-out clusters to fall back to
- // the useless "(Nf)" label when files are spread across many subdirectories.
- val scored = candidateSegments
- .map { case (seg, entries) =>
- seg -> entries.length * (1.0 + entries.map(_._1 / maxD).sum / entries.length)
- }
- val dominant = scored.maxByOption(_._2).map(_._1.capitalize)
- r.copy(label = dominant.getOrElse(r.label + s" (${r.memberFiles.size}f)"))
- }
+ r.copy(label = r.label + suffix)
case None => r
}
}