fix: backfill sessions indexed before content hashing (#21)
fix: backfill sessions indexed before content hashing (#21) Co-authored-by: David Gwilliam <dhgwilliam@gmail.com> Co-committed-by: David Gwilliam <dhgwilliam@gmail.com>
This commit was merged in pull request #21.
This commit is contained in:
@@ -21,8 +21,11 @@ const sessionWatermarkKey = "opencode_sync_max_updated"
|
||||
// It deliberately does not reconcile: RecordObservation updates the entry row
|
||||
// for the session it touched, and a full rebuild is disproportionate for a
|
||||
// handful of new turns.
|
||||
func IngestSessionsNow(kdb *db.KnoxDB) (created, changed, unchanged int, err error) {
|
||||
since, _ := strconv.ParseInt(kdb.Setting(sessionWatermarkKey), 10, 64)
|
||||
func IngestSessionsNow(kdb *db.KnoxDB, full bool) (created, changed, unchanged int, err error) {
|
||||
since := int64(0)
|
||||
if !full {
|
||||
since, _ = strconv.ParseInt(kdb.Setting(sessionWatermarkKey), 10, 64)
|
||||
}
|
||||
|
||||
results, err := ingest.NewOpenCodeDBIngester().IngestSince(since)
|
||||
if err != nil {
|
||||
@@ -95,8 +98,14 @@ func sessionNeedsWrite(kdb *db.KnoxDB, result *ingest.IngestResult) bool {
|
||||
return false
|
||||
}
|
||||
prev, err := kdb.LatestContentHash(result.Fingerprint)
|
||||
if err != nil || prev == "" {
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
if prev == "" {
|
||||
// No stored hash: nothing proves the indexed content is current. Write
|
||||
// once, then the hash makes later sweeps cheap. Without this, sessions
|
||||
// indexed before hashing existed would never pick up new content.
|
||||
return true
|
||||
}
|
||||
return prev != result.ContentHash
|
||||
}
|
||||
|
||||
@@ -695,7 +695,7 @@ func (w *Watcher) ingestGit() {
|
||||
// sweep is full every time; RecordObservation collapses unchanged sessions, so
|
||||
// no watermark is needed and repeated runs are idempotent.
|
||||
func (w *Watcher) ingestOpenCodeDB() {
|
||||
if _, _, _, err := IngestSessionsNow(w.knoxDB); err != nil {
|
||||
if _, _, _, err := IngestSessionsNow(w.knoxDB, false); err != nil {
|
||||
log.Printf("[knox] opencode.db ingest error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user