MCPcopy
hub / github.com/pocketbase/pocketbase / FindCachedCollectionByNameOrId

Method FindCachedCollectionByNameOrId

core/collection_query.go:99–113  ·  view source on GitHub ↗

FindCachedCollectionByNameOrId is similar to [BaseApp.FindCollectionByNameOrId] but retrieves the Collection from the app cache instead of making a db call. NB! This method is suitable for read-only Collection operations. Returns [sql.ErrNoRows] if no Collection is found for consistency with the [

(nameOrId string)

Source from the content-addressed store, hash-verified

97// - The cache is automatically updated on collections db change (create/update/delete).
98// To manually reload the cache you can call [BaseApp.ReloadCachedCollections].
99func (app *BaseApp) FindCachedCollectionByNameOrId(nameOrId string) (*Collection, error) {
100 collections, _ := app.Store().Get(StoreKeyCachedCollections).([]*Collection)
101 if collections == nil {
102 // cache is not initialized yet (eg. run in a system migration)
103 return app.FindCollectionByNameOrId(nameOrId)
104 }
105
106 for _, c := range collections {
107 if strings.EqualFold(c.Name, nameOrId) || c.Id == nameOrId {
108 return c, nil
109 }
110 }
111
112 return nil, sql.ErrNoRows
113}
114
115// FindCollectionReferences returns information for all relation fields
116// referencing the provided collection.

Callers

nothing calls this directly

Calls 3

StoreMethod · 0.95
GetMethod · 0.65

Tested by

no test coverage detected