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)
| 97 | // - The cache is automatically updated on collections db change (create/update/delete). |
| 98 | // To manually reload the cache you can call [BaseApp.ReloadCachedCollections]. |
| 99 | func (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. |
nothing calls this directly
no test coverage detected