fix: locking

This commit is contained in:
Jan Bader committed 2026-10-07 10:37:50 +02:00
1 parent c8a16d3f3e
commit 6041cc0a33
2 files changed
+24 -2

No files matched your search

+14 -2
View File
@@ -377,6 +377,8 @@ type lazyByIDNode struct {
client *DocspellClient
query string
limit int
mu sync.Mutex
shards map[string]*lazyByIDShardNode
}
type lazyByIDShardNode struct {
@@ -511,11 +513,21 @@ func (d *lazyByIDNode) Lookup(ctx context.Context, name string) (fs.Node, error)
if !isDocspellIDPrefix(name) {
return nil, fuse.ENOENT
}
return &lazyByIDShardNode{
d.mu.Lock()
defer d.mu.Unlock()
if d.shards == nil {
d.shards = map[string]*lazyByIDShardNode{}
}
shard, ok := d.shards[name]
if !ok {
shard = &lazyByIDShardNode{
query: combineItemQueries(d.query, "id:"+name+"*"),
client: d.client,
limit: d.limit,
}, nil
}
d.shards[name] = shard
}
return shard, nil
}
func (d *lazyByIDNode) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
+10
View File
@@ -104,6 +104,16 @@ func TestLazyByIDShardFetchesMatchingPrefix(t *testing.T) {
if _, err := shard.(*lazyByIDShardNode).Lookup(context.Background(), "it-item-1.pdf"); err != nil {
t.Fatal(err)
}
lookupAgain, err := byID.(*lazyByIDNode).Lookup(context.Background(), "it")
if err != nil {
t.Fatal(err)
}
if lookupAgain != shard {
t.Fatal("expected repeated shard lookup to return its cached node")
}
if _, err := lookupAgain.(*lazyByIDShardNode).Lookup(context.Background(), "it-item-1.pdf"); err != nil {
t.Fatal(err)
}
if len(queries) != 2 || queries[0] != "id:it*" || queries[1] != "id:it*" {
t.Fatalf("unexpected queries: %v", queries)
}