MCPcopy Index your code
hub / github.com/docker/docker-agent / getDatabase

Method getDatabase

pkg/modelsdev/store.go:155–184  ·  view source on GitHub ↗

getDatabase returns the models.dev database. When allowFetch is false the catalog is served from memory or the on-disk cache only and the network is never touched; a cache miss yields an empty database rather than an error.

(ctx context.Context, allowFetch bool)

Source from the content-addressed store, hash-verified

153// catalog is served from memory or the on-disk cache only and the network is
154// never touched; a cache miss yields an empty database rather than an error.
155func (s *Store) getDatabase(ctx context.Context, allowFetch bool) (*Database, error) {
156 s.mu.Lock()
157 defer s.mu.Unlock()
158
159 // The authoritative catalog, once loaded, serves every lookup — including
160 // fetch-disallowed ones, which then benefit from the fresher data.
161 if s.db != nil {
162 return s.db, nil
163 }
164
165 if !allowFetch {
166 // Serve (and memoize) a cache-only snapshot without touching the
167 // network. Kept out of s.db so it can never satisfy a later
168 // fetch-eligible lookup for a known provider.
169 if s.cacheDB == nil {
170 s.cacheDB, _ = loadDatabase(ctx, s.cacheFile, false, s.fetcher())
171 }
172 return s.cacheDB, nil
173 }
174
175 db, authoritative := loadDatabase(ctx, s.cacheFile, true, s.fetcher())
176 // Only memoize a result that came from the on-disk cache or a live fetch.
177 // The embedded fallback snapshot is deliberately NOT pinned, so a later
178 // lookup retries the fetch once the network (or cache) recovers instead of
179 // serving the build-time snapshot for the Store's entire lifetime.
180 if authoritative {
181 s.db = db
182 }
183 return db, nil
184}
185
186// fetcher returns the Store's catalog fetcher, defaulting to fetchFromAPI when
187// unset. The constructors always populate s.fetch, but defaulting here guards

Callers 2

GetDatabaseMethod · 0.95
getProviderMethod · 0.95

Calls 4

fetcherMethod · 0.95
loadDatabaseFunction · 0.85
LockMethod · 0.45
UnlockMethod · 0.45

Tested by

no test coverage detected