Skip to content

Commit

Permalink
fix more slow queries
Browse files Browse the repository at this point in the history
  • Loading branch information
abelanger5 committed Aug 1, 2024
1 parent ec519ad commit 0a1f55f
Show file tree
Hide file tree
Showing 14 changed files with 116 additions and 275 deletions.
2 changes: 0 additions & 2 deletions api-contracts/openapi/components/schemas/workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ Workflow:
items:
$ref: "#/WorkflowTag"
description: The tags of the workflow.
lastRun:
$ref: "./_index.yaml#/WorkflowRun"
jobs:
type: array
items:
Expand Down
2 changes: 1 addition & 1 deletion api/v1/server/handlers/workflows/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
func (t *WorkflowService) WorkflowGet(ctx echo.Context, request gen.WorkflowGetRequestObject) (gen.WorkflowGetResponseObject, error) {
workflow := ctx.Get("workflow").(*db.WorkflowModel)

resp, err := transformers.ToWorkflow(workflow, nil)
resp, err := transformers.ToWorkflow(workflow)

if err != nil {
return nil, err
Expand Down
6 changes: 1 addition & 5 deletions api/v1/server/handlers/workflows/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@ func (t *WorkflowService) WorkflowList(ctx echo.Context, request gen.WorkflowLis
rows := make([]gen.Workflow, len(listResp.Rows))

for i := range listResp.Rows {
workflow, err := transformers.ToWorkflow(listResp.Rows[i].WorkflowModel, listResp.Rows[i].LatestRun)

if err != nil {
return nil, err
}
workflow := transformers.ToWorkflowFromSQLC(listResp.Rows[i])

rows[i] = *workflow
}
Expand Down
175 changes: 87 additions & 88 deletions api/v1/server/oas/gen/openapi.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 6 additions & 11 deletions api/v1/server/oas/transformers/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,12 @@ import (
"github.com/hatchet-dev/hatchet/pkg/repository/prisma/dbsqlc"
)

func ToWorkflow(workflow *db.WorkflowModel, lastRun *db.WorkflowRunModel) (*gen.Workflow, error) {
func ToWorkflow(workflow *db.WorkflowModel) (*gen.Workflow, error) {
res := &gen.Workflow{
Metadata: *toAPIMetadata(workflow.ID, workflow.CreatedAt, workflow.UpdatedAt),
Name: workflow.Name,
}

if lastRun != nil {
var err error
res.LastRun, err = ToWorkflowRun(lastRun)

if err != nil {
return nil, err
}
}

if description, ok := workflow.Description(); ok {
res.Description = &description
}
Expand Down Expand Up @@ -160,7 +151,7 @@ func ToWorkflowVersion(workflow *db.WorkflowModel, version *db.WorkflowVersionMo

if workflow != nil {
var err error
res.Workflow, err = ToWorkflow(workflow, nil)
res.Workflow, err = ToWorkflow(workflow)

if err != nil {
return nil, err
Expand Down Expand Up @@ -338,6 +329,10 @@ func ToWorkflowFromSQLC(row *dbsqlc.Workflow) *gen.Workflow {
Description: &row.Description.String,
}

// if lastRunAt != nil && !lastRunAt.IsZero() {
// res.LastRunAt = lastRunAt
// }

return res
}

Expand Down
1 change: 0 additions & 1 deletion frontend/app/src/lib/api/generated/data-contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,6 @@ export interface Workflow {
versions?: WorkflowVersionMeta[];
/** The tags of the workflow. */
tags?: WorkflowTag[];
lastRun?: WorkflowRun;
/** The jobs of the workflow. */
jobs?: Job[];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,9 @@ export function WorkflowTable() {
<Link to={`/workflows/${data.metadata?.id}`}>{data.name}</Link>
</h3>
<p className="mt-1 max-w-2xl text-sm text-gray-700 dark:text-gray-300">
Last run{' '}
{data.lastRun?.metadata?.createdAt ? (
<RelativeDate date={data.lastRun?.metadata?.createdAt} />
) : (
'never'
)}
<br />
{/* Last run{' '}
{data.lastRunAt ? <RelativeDate date={data.lastRunAt} /> : 'never'}
<br /> */}
Created at <RelativeDate date={data.metadata?.createdAt} />
</p>
</div>
Expand Down
1 change: 0 additions & 1 deletion pkg/client/rest/gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/repository/prisma/dbsqlc/workflow_runs.sql
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ LEFT JOIN
"Workflow" as workflow ON workflowVersion."workflowId" = workflow."id"
WHERE
runs."tenantId" = @tenantId::uuid AND
runs."created" > NOW - INTERVAL '1 day' AND
runs."createdAt" > NOW - INTERVAL '1 day' AND
runs."deletedAt" IS NULL AND
workflowVersion."deletedAt" IS NULL AND
workflow."deletedAt" IS NULL AND
Expand Down
2 changes: 1 addition & 1 deletion pkg/repository/prisma/dbsqlc/workflow_runs.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0a1f55f

Please sign in to comment.