package loaders import ( "context" "git.aiterp.net/stufflog/server/database/repositories" "git.aiterp.net/stufflog/server/models" "time" ) // go run github.com/vektah/dataloaden LogsByIssueLoader string []\*git.aiterp.net/stufflog/server/models.Log var logsByIssueLoaderCtxKey = "ctx.stufflog.IssuesByLogLoader" func LogsByIssueLoaderFromContext(ctx context.Context) *LogsByIssueLoader { return ctx.Value(logsByIssueLoaderCtxKey).(*LogsByIssueLoader) } func NewLogsByIssueLoader(ctx context.Context, logsRepo repositories.LogRepository) *LogsByIssueLoader { return &LogsByIssueLoader{ fetch: func(keys []string) ([][]*models.Log, []error) { results := make([][]*models.Log, len(keys)) errors := make([]error, len(keys)) logs, err := logsRepo.List(ctx, models.LogFilter{IssueIDs: keys}) if err != nil { for i := range errors { errors[i] = err } return results, errors } for i, key := range keys { for _, log := range logs { if log.MatchesIssue(key) { results[i] = append(results[i], log) } } } return results, nil }, wait: time.Millisecond / 2, maxBatch: 16, } }