MCPcopy Index your code
hub / github.com/pocketbase/pocketbase / FindCachedCollectionReferences

Method FindCachedCollectionReferences

core/collection_query.go:165–188  ·  view source on GitHub ↗

FindCachedCollectionReferences is similar to [BaseApp.FindCollectionReferences] but retrieves the Collection from the app cache instead of making a db call. NB! This method is suitable for read-only Collection operations. If you plan making changes to the returned Collection model, use [BaseApp.Fi

(collection *Collection, excludeIds ...string)

Source from the content-addressed store, hash-verified

163// - The cache is automatically updated on collections db change (create/update/delete).
164// To manually reload the cache you can call [BaseApp.ReloadCachedCollections].
165func (app *BaseApp) FindCachedCollectionReferences(collection *Collection, excludeIds ...string) (map[*Collection][]Field, error) {
166 collections, _ := app.Store().Get(StoreKeyCachedCollections).([]*Collection)
167 if collections == nil {
168 // cache is not initialized yet (eg. run in a system migration)
169 return app.FindCollectionReferences(collection, excludeIds...)
170 }
171
172 result := map[*Collection][]Field{}
173
174 for _, c := range collections {
175 if slices.Contains(excludeIds, c.Id) {
176 continue
177 }
178
179 for _, rawField := range c.Fields {
180 f, ok := rawField.(*RelationField)
181 if ok && f.CollectionId == collection.Id {
182 result[c] = append(result[c], f)
183 }
184 }
185 }
186
187 return result, nil
188}
189
190// IsCollectionNameUnique checks that there is no existing collection
191// with the provided name (case insensitive!).

Callers

nothing calls this directly

Calls 3

StoreMethod · 0.95
GetMethod · 0.65

Tested by

no test coverage detected