~sircmpwn/sr.ht-dev

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
2 2

[PATCH builds.sr.ht] api: pass job owner to StartJobGroupUnsafe()

Details
Message ID
<20221125160756.301445-1-ch@bitfehler.net>
DKIM signature
pass
Download raw message
Patch: +7 -5
This allows it to make use of the index on `owner_id` in the `job`
table. Without this, the query it makes is prohibitively expensive. A
sample query analysis went from > 1800 ms without the index to < 1ms
when using the index.
---
 api/graph/resolver.go         | 8 +++++---
 api/graph/schema.resolvers.go | 4 ++--
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/api/graph/resolver.go b/api/graph/resolver.go
index ad9020c..9e30065 100644
--- a/api/graph/resolver.go
+++ b/api/graph/resolver.go
@@ -66,7 +66,7 @@ func FetchLogs(ctx context.Context, url string) (*model.Log, error) {
}

// Starts a job group. Does not authenticate the user.
func StartJobGroupUnsafe(ctx context.Context, tx *sql.Tx, id int) error {
func StartJobGroupUnsafe(ctx context.Context, tx *sql.Tx, id, ownerID int) error {
	var manifests []struct {
		ID       int
		Manifest *Manifest
@@ -74,9 +74,11 @@ func StartJobGroupUnsafe(ctx context.Context, tx *sql.Tx, id int) error {

	rows, err := tx.QueryContext(ctx, `
		UPDATE job SET status = 'queued'
		WHERE job_group_id = $1
		WHERE
			job_group_id = $1 AND
			owner_id = $2
		RETURNING id, manifest;
	`, id)
	`, id, ownerID)
	if err != nil {
		return err
	}
diff --git a/api/graph/schema.resolvers.go b/api/graph/schema.resolvers.go
index 41541cb..23b4d1e 100644
--- a/api/graph/schema.resolvers.go
+++ b/api/graph/schema.resolvers.go
@@ -540,7 +540,7 @@ func (r *mutationResolver) CreateGroup(ctx context.Context, jobIds []int, trigge
			return nil
		}

		return StartJobGroupUnsafe(ctx, tx, group.ID)
		return StartJobGroupUnsafe(ctx, tx, group.ID, group.OwnerID)
	}); err != nil {
		return nil, err
	}
@@ -566,7 +566,7 @@ func (r *mutationResolver) StartGroup(ctx context.Context, groupID int) (*model.
			return err
		}

		return StartJobGroupUnsafe(ctx, tx, groupID)
		return StartJobGroupUnsafe(ctx, tx, groupID, group.OwnerID)
	}); err != nil {
		return nil, err
	}
-- 
2.38.1
Details
Message ID
<IO3Vi6Ksh-wF6qtW4pJXshEj6hhco3nbT9vN3lhvauLgMZPUBNm0XdEIqKDFFeSPqzIUCnwxchZHPqLxBq_mHoB3Iqi3xcMqylNx5Y0sWh8=@emersion.fr>
In-Reply-To
<20221125160756.301445-1-ch@bitfehler.net> (view parent)
DKIM signature
pass
Download raw message
Looks good.

Are there other places where we select on job_group_id? Maybe it would
be a good idea to create an index for this column regardless.
Details
Message ID
<CON48AU5WQIR.2ZNQO2ZNIDSAV@megumin>
In-Reply-To
<IO3Vi6Ksh-wF6qtW4pJXshEj6hhco3nbT9vN3lhvauLgMZPUBNm0XdEIqKDFFeSPqzIUCnwxchZHPqLxBq_mHoB3Iqi3xcMqylNx5Y0sWh8=@emersion.fr> (view parent)
DKIM signature
pass
Download raw message
Thanks!

To git@git.sr.ht:~sircmpwn/builds.sr.ht
   eaf435b..292dc73  master -> master
Reply to thread Export thread (mbox)