Skip to content

Commit

Permalink
Only instantiate collection object when necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
philippgille committed Feb 25, 2024
1 parent acccec0 commit 407db96
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,18 @@ func NewPersistentDB(path string) (*DB, error) {
// and documents.
// TODO: Parallelize this (e.g. chan with $numCPU buffer and $numCPU goroutines
// reading from it).
collectionPath := filepath.Join(path, dirEntry.Name())
collectionDirEntries, err := os.ReadDir(collectionPath)
if err != nil {
return nil, fmt.Errorf("couldn't read collection directory: %w", err)
}
c := &Collection{
// We can fill Name, persistDirectory and metadata only after reading
// the metadata.
documents: make(map[string]*document),
// We can fill embed only when the user calls DB.GetCollection() or
// DB.GetOrCreateCollection().
}
collectionPath := filepath.Join(path, dirEntry.Name())
collectionDirEntries, err := os.ReadDir(collectionPath)
if err != nil {
return nil, fmt.Errorf("couldn't read collection directory: %w", err)
}
for _, collectionDirEntry := range collectionDirEntries {
// Files should be metadata and documents; skip subdirectories which
// the user might have placed.
Expand Down

0 comments on commit 407db96

Please sign in to comment.