Shard by-id mount entries
This commit is contained in:
@@ -123,12 +123,25 @@ func buildMountTree(ctx context.Context, client *DocspellClient, items []SearchI
|
|||||||
byIDName = fmt.Sprintf("%s-%d%s", item.ID, i+1, ext)
|
byIDName = fmt.Sprintf("%s-%d%s", item.ID, i+1, ext)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
byID.children[uniqueName(byID.children, sanitizeName(byIDName))] = node
|
shard := idShard(item.ID)
|
||||||
|
shardDir := ensureDir(byID, shard)
|
||||||
|
shardDir.children[uniqueName(shardDir.children, sanitizeName(byIDName))] = node
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return root
|
return root
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func idShard(id string) string {
|
||||||
|
id = sanitizeName(id)
|
||||||
|
if len(id) >= 2 {
|
||||||
|
return id[:2]
|
||||||
|
}
|
||||||
|
if id != "" {
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
return "__"
|
||||||
|
}
|
||||||
|
|
||||||
func ensureDir(root *dirNode, first string, rest ...string) *dirNode {
|
func ensureDir(root *dirNode, first string, rest ...string) *dirNode {
|
||||||
cur := root
|
cur := root
|
||||||
parts := append([]string{first}, rest...)
|
parts := append([]string{first}, rest...)
|
||||||
|
|||||||
+6
-2
@@ -87,9 +87,13 @@ func TestBuildMountTreeAddsByIDDirectory(t *testing.T) {
|
|||||||
if !ok {
|
if !ok {
|
||||||
t.Fatalf("expected by-id directory, got %#v", root.children)
|
t.Fatalf("expected by-id directory, got %#v", root.children)
|
||||||
}
|
}
|
||||||
|
shard, ok := byID.children["it"].(*dirNode)
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("expected by-id shard, got %#v", byID.children)
|
||||||
|
}
|
||||||
for _, name := range []string{"item-1.pdf", "item-1-2.txt", "item-1-3.pdf"} {
|
for _, name := range []string{"item-1.pdf", "item-1-2.txt", "item-1-3.pdf"} {
|
||||||
if _, ok := byID.children[name].(*fileNode); !ok {
|
if _, ok := shard.children[name].(*fileNode); !ok {
|
||||||
t.Fatalf("expected %s in by-id, got %#v", name, byID.children)
|
t.Fatalf("expected %s in by-id shard, got %#v", name, shard.children)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user