From ca901140543e44b22c31d164c031fd028ef721d0 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Tue, 24 Nov 2020 13:00:21 -0500 Subject: [PATCH] API: simplify ACL relationship implementations --- api/graph/schema.resolvers.go | 40 ++--------------------------------- 1 file changed, 2 insertions(+), 38 deletions(-) diff --git a/api/graph/schema.resolvers.go b/api/graph/schema.resolvers.go index 3a460e2..40a3174 100644 --- a/api/graph/schema.resolvers.go +++ b/api/graph/schema.resolvers.go @@ -25,47 +25,11 @@ import ( ) func (r *aCLResolver) Repository(ctx context.Context, obj *model.ACL) (*model.Repository, error) { - // XXX This could be moved into a loader, but it's unlikely to be a - // frequently utilized endpoint, so I'm not especially interested in the - // extra work/cruft. - repo := (&model.Repository{}).As(`repo`) - if err := database.WithTx(ctx, &sql.TxOptions{ - Isolation: 0, - ReadOnly: true, - }, func(tx *sql.Tx) error { - query := database. - Select(ctx, repo). - From(`repository repo`). - Join(`access acl ON acl.repo_id = repo.id`). - Where(`acl.id = ?`, obj.ID) - row := query.RunWith(tx).QueryRow() - return row.Scan(database.Scan(ctx, repo)...) - }); err != nil { - panic(err) // Invariant - } - return repo, nil + return loaders.ForContext(ctx).RepositoriesByID.Load(obj.RepoID) } func (r *aCLResolver) Entity(ctx context.Context, obj *model.ACL) (model.Entity, error) { - // XXX This could be moved into a loader, but it's unlikely to be a - // frequently utilized endpoint, so I'm not especially interested in the - // extra work/cruft. - user := (&model.User{}).As(`u`) - if err := database.WithTx(ctx, &sql.TxOptions{ - Isolation: 0, - ReadOnly: true, - }, func(tx *sql.Tx) error { - query := database. - Select(ctx, user). - From(`"user" u`). - Join(`access acl ON acl.user_id = u.id`). - Where(`acl.id = ?`, obj.ID) - row := query.RunWith(tx).QueryRow() - return row.Scan(database.Scan(ctx, user)...) - }); err != nil { - panic(err) // Invariant - } - return user, nil + return loaders.ForContext(ctx).UsersByID.Load(obj.UserID) } func (r *artifactResolver) URL(ctx context.Context, obj *model.Artifact) (string, error) { -- 2.38.4