From b76c8bb4a5da27b51161c6899fdce0e406dc6561 Mon Sep 17 00:00:00 2001 From: Matt Johnson-Pint Date: Fri, 6 Dec 2024 14:04:03 -0800 Subject: [PATCH] . --- runtime/collections/collection.go | 2 +- runtime/collections/factory.go | 5 +++-- runtime/collections/vector.go | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/runtime/collections/collection.go b/runtime/collections/collection.go index 8b10aaaa..93dffc60 100644 --- a/runtime/collections/collection.go +++ b/runtime/collections/collection.go @@ -27,7 +27,7 @@ func newCollection() *collection { } func (c *collection) getCollectionNamespaceMap() map[string]interfaces.CollectionNamespace { - m := make(map[string]interfaces.CollectionNamespace) + m := make(map[string]interfaces.CollectionNamespace, c.collectionNamespaceMap.Size()) c.collectionNamespaceMap.Range(func(key string, value interfaces.CollectionNamespace) bool { m[key] = value return true diff --git a/runtime/collections/factory.go b/runtime/collections/factory.go index 262f40b2..b3c6e173 100644 --- a/runtime/collections/factory.go +++ b/runtime/collections/factory.go @@ -19,6 +19,7 @@ import ( "github.com/hypermodeinc/modus/runtime/collections/index/interfaces" "github.com/hypermodeinc/modus/runtime/db" "github.com/hypermodeinc/modus/runtime/logger" + "github.com/puzpuzpuz/xsync/v3" ) const collectionFactoryWriteInterval = 1 @@ -40,7 +41,7 @@ func newCollectionFactory() *collectionFactory { return &collectionFactory{ collectionMap: map[string]*collection{ "": { - collectionNamespaceMap: map[string]interfaces.CollectionNamespace{}, + collectionNamespaceMap: xsync.NewMapOf[string, interfaces.CollectionNamespace](), }, }, quit: make(chan struct{}), @@ -86,7 +87,7 @@ func (cf *collectionFactory) readFromPostgres(ctx context.Context) bool { resetTimerFaster := false var err error for _, namespaceCollectionFactory := range cf.collectionMap { - for _, col := range namespaceCollectionFactory.collectionNamespaceMap { + for _, col := range namespaceCollectionFactory.getCollectionNamespaceMap() { resetTimerFaster, err = loadTextsIntoCollection(ctx, col) if err != nil { logger.Err(ctx, err). diff --git a/runtime/collections/vector.go b/runtime/collections/vector.go index e04fca7f..aedb640c 100644 --- a/runtime/collections/vector.go +++ b/runtime/collections/vector.go @@ -98,7 +98,7 @@ func deleteIndexesNotInManifest(ctx context.Context, man *manifest.Manifest) { Msg("Failed to find collection.") continue } - for _, collNs := range col.collectionNamespaceMap { + for _, collNs := range col.getCollectionNamespaceMap() { vectorIndexMap := collNs.GetVectorIndexMap() if vectorIndexMap == nil { continue @@ -160,7 +160,7 @@ func processManifestCollections(ctx context.Context, man *manifest.Manifest) { } } } - for _, collNs := range col.collectionNamespaceMap { + for _, collNs := range col.getCollectionNamespaceMap() { for searchMethodName, searchMethod := range collectionInfo.SearchMethods { vi, err := collNs.GetVectorIndex(ctx, searchMethodName)