Skip to content
quarry Artifact [ca4a8c15b6]
Login

Artifact [ca4a8c15b6]

Artifact ca4a8c15b6673d5a00f007abf337394c13897e79485ff470ef7fb183688093a3:


// finfowarm.go — build the file-history index off the request path.
//
// zit answers `log CHECKIN PATH` from an index it derives on first use
// (zit#188, shipped 0.3.14, made durable across commits in 0.3.15).
// Measured on this fleet's SQLite mirror: 104s to build, then ~0.6s for
// ANY path, because the index is per repository rather than per path.
//
// 104 seconds is not a page. So the build is done here, beside the
// listing warm and under the same guard, rather than by whichever
// reader happens to open a file's history first.
package main

import (
	"context"
	"log"
	"time"

	"craftdesign.group/quarry/internal/zitcli"
)

// warmFinfoPath is the path the warming query asks about.
//
// Deliberately one that cannot exist. A PATH query builds the whole
// index before it discovers the path is not in the tree — verified on
// this fleet — so the index is warmed without reading any real file's
// history, and without quarry needing to know a tracked path to name.
// The leading dot and the name say what it is if it ever shows up in a
// log or a trace.
const warmFinfoPath = ".quarry-warm-file-index"

// warmFileHistory builds or extends the index, and says how long it took
// when that was long enough to matter.
//
// Errors are dropped on purpose: the query names a path that does not
// exist, so "no such path" IS the success case, and a store that cannot
// answer at all has already announced itself through ingest. The only
// cost of a failure here is that the next reader of a file's history
// pays what this would have.
func warmFileHistory(cli *zitcli.Client, tip, repo string) {
	start := time.Now()
	_, _ = cli.FileHistory(context.Background(), tip, warmFinfoPath, 1)
	// A warm index answers in well under a second; anything near the
	// build cost means this repository had none, which is worth one
	// line saying where the time went.
	if d := time.Since(start); d > 5*time.Second {
		log.Printf("file-history index for %s built in %s", repo, d.Round(time.Second))
	}
}