返回 DeepSeek-Reasonix
history_preparation.go
根目录 / internal / session / history_preparation.go
1 package session
2
3 import (
4 "context"
5 "path/filepath"
6 )
7
8 // Existing but obsolete indexes need the same background lifecycle as missing
9 // indexes. A reader must not wait on a whole-log rebuild or its mutex.
10 func (q *Query) historyLocatorReady(ctx context.Context, filesystem *FilesystemPersistence, sessionID, path string) (bool, error) {
11 if err := ctx.Err(); err != nil {
12 return false, err
13 }
14 lock := q.projectionLock("history", sessionID)
15 if !lock.TryLock() {
16 return false, nil
17 }
18 dir := filepath.Join(filesystem.Root, sessionID)
19 revision, err := revisionOfLog(dir)
20 current := err == nil && historyIndexCurrent(ctx, dir, path, sessionID, revision)
21 lock.Unlock()
22 if err != nil {
23 return false, err
24 }
25 if current {
26 return true, nil
27 }
28 preparation := q.prepareHistoryLocator(filesystem, sessionID, path)
29 select {
30 case <-preparation.done:
31 return preparation.err == nil, preparation.err
32 default:
33 return false, nil
34 }
35 }
36
36 lines GO