From 407db963f19b52e5ec2fb457d7a400913a982963 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Gill=C3=A9?= Date: Sun, 25 Feb 2024 20:06:36 +0100 Subject: [PATCH] Only instantiate collection object when necessary --- db.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/db.go b/db.go index 855806f..ad4103a 100644 --- a/db.go +++ b/db.go @@ -76,6 +76,11 @@ 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. @@ -83,11 +88,6 @@ func NewPersistentDB(path string) (*DB, error) { // 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.