Documentation
¶
Index ¶
- func GetByID[k comparable, t any](ctx context.Context, loader *dataloader.Loader[k, t], id k) (t, error)
- func GetMany[k comparable, t any](ctx context.Context, loader *dataloader.Loader[k, t], ids []k) ([]t, error)
- func NewMemoryLoaderCache[K comparable, V any](ctx context.Context, cacheKey string, expiration time.Duration) dataloader.Cache[K, V]
- func WithOnDelete(cb func()) any
- type BatchLoaders
- type Collection
- type HasKey
- type Loader
- type LoaderCache
- type LoadersWithPermissions
- type MemoryCache
- type Option
- type PersonalizedLoaders
- type ProfileLoaders
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetByID ¶
func GetByID[k comparable, t any](ctx context.Context, loader *dataloader.Loader[k, t], id k) (t, error)
GetByID returns the object from the loader
func GetMany ¶
func GetMany[k comparable, t any](ctx context.Context, loader *dataloader.Loader[k, t], ids []k) ([]t, error)
GetMany retrieves multiple items from specified loader
func NewMemoryLoaderCache ¶
func NewMemoryLoaderCache[K comparable, V any](ctx context.Context, cacheKey string, expiration time.Duration) dataloader.Cache[K, V]
NewMemoryLoaderCache returns a new memory cache
func WithOnDelete ¶
func WithOnDelete(cb func()) any
WithOnDelete tells the collection to run this function when entry is deleted
Types ¶
type BatchLoaders ¶
type BatchLoaders struct {
ApplicationLoader *Loader[int, *common.Application]
ApplicationIDFromCodeLoader *Loader[string, *common.Mapping[string, int]]
ApplicationGroupLoader *Loader[uuid.UUID, *common.ApplicationGroup]
RedirectLoader *Loader[uuid.UUID, *common.Redirect]
RedirectIDFromCodeLoader *Loader[string, *common.Mapping[string, uuid.UUID]]
PageLoader *Loader[int, *common.Page]
PageIDFromCodeLoader *Loader[string, *common.Mapping[string, int]]
CollectionIDFromSlugLoader *Loader[string, *common.Mapping[string, int]]
SectionLoader *Loader[int, *common.Section]
CollectionLoader *Loader[int, *common.Collection]
CollectionItemLoader *Loader[int, []*common.CollectionItem]
StudyTopicLoader *Loader[uuid.UUID, *common.StudyTopic]
StudyLessonLoader *Loader[uuid.UUID, *common.Lesson]
StudyTaskLoader *Loader[uuid.UUID, *common.Task]
StudyQuestionAlternativesLoader *Loader[uuid.UUID, []*common.QuestionAlternative]
ShowLoader *Loader[int, *common.Show]
SeasonLoader *Loader[int, *common.Season]
EpisodeLoader *Loader[int, *common.Episode]
EpisodeIDFromLegacyIDLoader *Loader[int, *common.Mapping[int, int]]
EpisodeIDFromLegacyProgramIDLoader *Loader[int, *common.Mapping[int, int]]
LinkLoader *Loader[int, *common.Link]
PlaylistLoader *Loader[uuid.UUID, *common.Playlist]
FilesLoader *Loader[int, []*common.File]
StreamsLoader *Loader[int, []*common.Stream]
AssetFilesLoader *Loader[int, []*common.File]
AssetStreamsLoader *Loader[int, []*common.Stream]
EventLoader *Loader[int, *common.Event]
EventEntriesLoader *Loader[int, []*common.Mapping[int, int]]
FAQCategoryLoader *Loader[uuid.UUID, *common.FAQCategory]
QuestionLoader *Loader[uuid.UUID, *common.Question]
MessageGroupLoader *Loader[int, *common.MessageGroup]
SurveyLoader *Loader[uuid.UUID, *common.Survey]
SurveyQuestionLoader *Loader[uuid.UUID, *common.SurveyQuestion]
GameLoader *Loader[uuid.UUID, *common.Game]
ShortLoader *Loader[uuid.UUID, *common.Short]
ShortsMediaIDLoader *Loader[uuid.UUID, *common.Mapping[uuid.UUID, uuid.UUID]]
MemberLoader *Loader[int, *members.Member]
OrganizationLoader *Loader[uuid.UUID, *members.Organization]
EpisodeProgressLoader *Loader[uuid.UUID, []*common.Mapping[uuid.UUID, int]]
EpisodeIDFromUuidLoader *Loader[uuid.UUID, *common.Mapping[uuid.UUID, int]]
ShowIDFromUuidLoader *Loader[uuid.UUID, *common.Mapping[uuid.UUID, int]]
// Permissions
ShowPermissionLoader *Loader[int, *common.Permissions[int]]
SeasonPermissionLoader *Loader[int, *common.Permissions[int]]
EpisodePermissionLoader *Loader[int, *common.Permissions[int]]
PagePermissionLoader *Loader[int, *common.Permissions[int]]
SectionPermissionLoader *Loader[int, *common.Permissions[int]]
CompletedTopicsLoader *Loader[uuid.UUID, []*common.Mapping[uuid.UUID, uuid.UUID]]
CompletedLessonsLoader *Loader[uuid.UUID, []*common.Mapping[uuid.UUID, uuid.UUID]]
CompletedTasksLoader *Loader[uuid.UUID, []*common.Mapping[uuid.UUID, uuid.UUID]]
CompletedAndLockedTasksLoader *Loader[uuid.UUID, []*common.Mapping[uuid.UUID, uuid.UUID]]
// Achievements
AchievementLoader *Loader[uuid.UUID, *common.Achievement]
AchievementGroupLoader *Loader[uuid.UUID, *common.AchievementGroup]
AchievementsLoader *Loader[uuid.UUID, []*common.Mapping[uuid.UUID, uuid.UUID]]
UnconfirmedAchievementsLoader *Loader[uuid.UUID, []*common.Mapping[uuid.UUID, uuid.UUID]]
AchievementGroupAchievementsLoader *Loader[uuid.UUID, []*common.Mapping[uuid.UUID, uuid.UUID]]
ComputedDataLoader *Loader[uuid.UUID, []*common.ComputedData]
UserLoader *Loader[string, *common.User]
// UserCollections
UserCollectionLoader *Loader[uuid.UUID, *common.UserCollection]
UserCollectionEntryLoader *Loader[uuid.UUID, *common.UserCollectionEntry]
UserCollectionEntryIDsLoader *Loader[uuid.UUID, []*common.Mapping[uuid.UUID, uuid.UUID]]
ProfileUserCollectionIDsLoader *Loader[uuid.UUID, []*common.Mapping[uuid.UUID, uuid.UUID]]
ProfileMyListCollectionID *Loader[uuid.UUID, *common.Mapping[uuid.UUID, uuid.UUID]]
PromptLoader *Loader[uuid.UUID, *common.Prompt]
MediaItemPrimaryEpisodeIDLoader *Loader[uuid.UUID, *common.Mapping[uuid.UUID, int]]
TimedMetadataLoader *Loader[uuid.UUID, *common.TimedMetadata]
ChaptersLoader *Loader[int, []*common.TimedMetadata]
PersonLoader *Loader[uuid.UUID, *common.Person]
SongLoader *Loader[uuid.UUID, *common.Song]
SongCollectionLoader *Loader[uuid.UUID, *common.SongCollection]
SongIDsForMediaItemLoader *Loader[uuid.UUID, []*common.Mapping[uuid.UUID, uuid.UUID]]
SongContributionsLoader *Loader[uuid.UUID, []*common.SongContribution]
EpisodeContributionsLoader *Loader[int, []*common.EpisodeContribution]
PhraseLoader *Loader[string, *common.Phrase]
ContributionsLoader *Loader[int32, *common.Contribution]
}
BatchLoaders contains loaders for the different items
func InitBatchLoaders ¶
func InitBatchLoaders(queries *sqlc.Queries, membersClient *members.Client) *BatchLoaders
type Collection ¶
type Collection[K comparable, V any] struct { // contains filtered or unexported fields }
Collection is a collection of loaders or other advanced structures
func NewCollection ¶
func NewCollection[K comparable, V any](expiration time.Duration) *Collection[K, V]
NewCollection of loaders or other structures
func (Collection[K, V]) Delete ¶
func (c Collection[K, V]) Delete(key K)
Delete the specified key (&entry)
func (Collection[K, V]) DeleteExpired ¶
func (c Collection[K, V]) DeleteExpired()
DeleteExpired entries
func (Collection[K, V]) Get ¶
func (c Collection[K, V]) Get(key K) (value V, ok bool)
Get a value by the specified key
func (Collection[K, V]) Set ¶
func (c Collection[K, V]) Set(key K, value V, opts ...any)
Set a key to specified value
type HasKey ¶
type HasKey[k comparable] interface { GetKey() k }
HasKey interface for items with keys
type Loader ¶
type Loader[K comparable, V any] struct { *dataloader.Loader[K, V] }
Loader contains loader and additional functions to retrieve data easily
func New ¶
func New[K comparable, V any]( ctx context.Context, factory func(ctx context.Context, ids []K) ([]V, error), opts ...Option, ) *Loader[K, *V]
New creates a single-value batch loader. The factory returns []V; the key used to index each value is supplied via WithKeyFunc, WithIdentityKey, or V implementing HasKey[K].
func NewListLoader ¶
func NewListLoader[K comparable, V any]( ctx context.Context, factory func(ctx context.Context, ids []K) ([]V, error), opts ...Option, ) *Loader[K, []*V]
NewListLoader returns a configured batch loader for one-to-many lookups. The key for each row is resolved via WithKeyFunc, WithIdentityKey, or V implementing HasKey[K] — same rules as New.
type LoaderCache ¶
type LoaderCache[K comparable, V any] struct { // contains filtered or unexported fields }
LoaderCache is a cache for batchloaders
func (*LoaderCache[K, V]) Delete ¶
func (c *LoaderCache[K, V]) Delete(_ context.Context, key K) bool
Delete deletes the specified key
func (*LoaderCache[K, V]) Get ¶
func (c *LoaderCache[K, V]) Get(_ context.Context, key K) (dataloader.Thunk[V], bool)
Get retrieves an entry from the cache
func (*LoaderCache[K, V]) Set ¶
func (c *LoaderCache[K, V]) Set(_ context.Context, key K, val dataloader.Thunk[V])
Set sets the specified key to value
type LoadersWithPermissions ¶
type LoadersWithPermissions struct {
Key string
EpisodeFilterLoader *Loader[int, *int]
EpisodeUUIDFilterLoader *Loader[uuid.UUID, *uuid.UUID]
EpisodesLoader *Loader[int, []*common.Mapping[int, int]]
SeasonFilterLoader *Loader[int, *int]
SeasonsLoader *Loader[int, []*common.Mapping[int, int]]
ShowFilterLoader *Loader[int, *int]
ShowUUIDFilterLoader *Loader[uuid.UUID, *uuid.UUID]
SectionsLoader *Loader[int, []*common.Mapping[int, int]]
CalendarEntryLoader *Loader[int, *common.CalendarEntry]
StudyTopicFilterLoader *Loader[uuid.UUID, *uuid.UUID]
StudyLessonsLoader *Loader[uuid.UUID, []*common.Mapping[uuid.UUID, uuid.UUID]]
StudyLessonFilterLoader *Loader[uuid.UUID, *uuid.UUID]
StudyTasksLoader *Loader[uuid.UUID, []*common.Mapping[uuid.UUID, uuid.UUID]]
StudyTaskFilterLoader *Loader[uuid.UUID, *uuid.UUID]
SurveyQuestionsLoader *Loader[uuid.UUID, []*common.Mapping[uuid.UUID, uuid.UUID]]
FAQQuestionsLoader *Loader[uuid.UUID, []*common.Mapping[uuid.UUID, uuid.UUID]]
//Relations
StudyLessonEpisodesLoader *Loader[uuid.UUID, []*common.Mapping[uuid.UUID, int]]
EpisodeStudyLessonsLoader *Loader[int, []*common.Mapping[int, uuid.UUID]]
StudyLessonLinksLoader *Loader[uuid.UUID, []*common.Mapping[uuid.UUID, int]]
LinkStudyLessonsLoader *Loader[int, []*common.Mapping[int, uuid.UUID]]
// Lists
PromptIDsLoader func(ctx context.Context) ([]uuid.UUID, error)
FAQCategoryIDsLoader func(ctx context.Context) ([]uuid.UUID, error)
ShortIDsLoader func(ctx context.Context) ([][]uuid.UUID, error)
ShortWithScoresLoader func(ctx context.Context) ([]common.ShortIDWithMeta, error)
}
LoadersWithPermissions contains loaders that will be filtered by permissions.
func GetLoadersForRoles ¶
func GetLoadersForRoles(queries *sqlc.Queries, roles []string) *LoadersWithPermissions
type MemoryCache ¶
type MemoryCache struct {
// contains filtered or unexported fields
}
MemoryCache is a simple memory cache
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option is the interface for all options
func WithIdentityKey ¶
func WithIdentityKey() Option
WithIdentityKey signals that the factory's items already _are_ the keys (typical for filter / ACL loaders that return the subset of input keys the caller has access to). Equivalent to WithKeyFunc(func(v V) K { return v.(K) }), but without forcing the call site to spell the type. Panics at first batch if V is not assignable to K.
func WithKeyFunc ¶
func WithKeyFunc[K comparable, V any](getKey func(V) K) Option
WithKeyFunc specifies that the key should be retrieved with this function.
func WithMemoryCache ¶
WithMemoryCache defines how long a key should live in the cache
type PersonalizedLoaders ¶
type PersonalizedLoaders struct {
Key string
CollectionItemsLoader *Loader[int, []*common.CollectionItem]
ContributionsForPersonLoader *Loader[uuid.UUID, []*common.Contribution]
TagEpisodesLoader *Loader[int, []*common.Mapping[int, int]]
}
PersonalizedLoaders contains loaders that are personalized to the user
This includes things like permissions, settings, langauges, etc
func GetPersonalizedLoaders ¶
func GetPersonalizedLoaders( queries *sqlc.Queries, roles []string, languagePreferences common.LanguagePreferences, ) *PersonalizedLoaders
type ProfileLoaders ¶
type ProfileLoaders struct {
ProgressLoader *Loader[int, *common.Progress]
TaskCompletedLoader *Loader[uuid.UUID, *uuid.UUID]
TaskAlternativesAnswersCountLoader *Loader[uuid.UUID, *common.AlternativesTasksProgress]
AchievementAchievedAtLoader *Loader[uuid.UUID, *common.Achieved]
GetSelectedAlternativesLoader *Loader[uuid.UUID, *common.SelectedAlternatives]
SeasonDefaultEpisodeLoader *Loader[int, *common.Mapping[int, int]]
ShowDefaultEpisodeLoader *Loader[int, *common.Mapping[int, int]]
MediaProgressLoader *Loader[uuid.UUID, *common.MediaProgress]
TopicDefaultLessonLoader *Loader[uuid.UUID, *common.Mapping[uuid.UUID, uuid.UUID]]
}
ProfileLoaders contains loaders per profile