Skip to content

Commit faea562

Browse files
committed
Simplify NewStore by using sync.OnceValues directly
Assisted-By: docker-agent
1 parent 311a7e1 commit faea562

1 file changed

Lines changed: 6 additions & 14 deletions

File tree

pkg/modelsdev/store.go

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,12 @@ type Store struct {
3434
etag string // ETag from last successful fetch, used for conditional requests
3535
}
3636

37-
// singleton holds the process-wide Store instance. It is initialised lazily
38-
// on the first call to NewStore. All subsequent calls return the same value.
39-
var singleton = sync.OnceValues(func() (*Store, error) {
37+
// NewStore returns the process-wide singleton Store.
38+
//
39+
// The database is loaded lazily on the first call to GetDatabase and
40+
// then cached in memory so that every caller shares one copy.
41+
// The first call creates the cache directory if it does not exist.
42+
var NewStore = sync.OnceValues(func() (*Store, error) {
4043
homeDir, err := os.UserHomeDir()
4144
if err != nil {
4245
return nil, fmt.Errorf("failed to get user home directory: %w", err)
@@ -52,15 +55,6 @@ var singleton = sync.OnceValues(func() (*Store, error) {
5255
}, nil
5356
})
5457

55-
// NewStore returns the process-wide singleton Store.
56-
//
57-
// The database is loaded lazily on the first call to GetDatabase and
58-
// then cached in memory so that every caller shares one copy.
59-
// The first call creates the cache directory if it does not exist.
60-
func NewStore() (*Store, error) {
61-
return singleton()
62-
}
63-
6458
// NewDatabaseStore creates a Store pre-populated with the given database.
6559
// The returned store serves data entirely from memory and never fetches
6660
// from the network or touches the filesystem, making it suitable for
@@ -329,5 +323,3 @@ var bedrockRegionPrefixes = map[string]bool{
329323
func isBedrockRegionPrefix(prefix string) bool {
330324
return bedrockRegionPrefixes[prefix]
331325
}
332-
333-

0 commit comments

Comments
 (0)