Skip to content

Commit

Permalink
improve run query time
Browse files Browse the repository at this point in the history
  • Loading branch information
hughcrt committed Jun 18, 2024
1 parent 709806f commit a3a41c9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 21 deletions.
24 changes: 3 additions & 21 deletions packages/backend/src/api/v1/runs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,39 +150,21 @@ runs.get("/", async (ctx: Context) => {
eu.last_seen as user_last_seen,
eu.props as user_props,
t.slug as template_slug,
rpfc.feedback as parent_feedback,
coalesce(array_agg(
jsonb_build_object(
'evaluatorName', e.name,
'evaluatorSlug', e.slug,
'evaluatorId', e.id,
'result', er.result,
'createdAt', er.created_at,
'updatedAt', er.updated_at
)
) filter (where er.run_id is not null), '{}') as evaluation_results
rpfc.feedback as parent_feedback
from
public.run r
run r
left join external_user eu on r.external_user_id = eu.id
left join run_parent_feedback_cache rpfc on r.id = rpfc.id
left join template_version tv on r.template_version_id = tv.id
left join template t on tv.template_id = t.id
left join evaluation_result_v2 er on r.id = er.run_id
left join evaluator e on er.evaluator_id = e.id
where
r.project_id = ${projectId}
${parentRunCheck}
and (${filtersQuery})
group by
r.id,
eu.id,
t.slug,
rpfc.feedback
order by
r.created_at desc
limit ${exportType ? 10000 : Number(limit)}
offset ${Number(page) * Number(limit)}
`
offset ${Number(page) * Number(limit)}`

const runs = rows.map(formatRun)

Expand Down
5 changes: 5 additions & 0 deletions packages/backend/src/utils/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ function debugFn(
parameters: any[],
paramTypes: any[],
) {
// for (let i = 0; i <= parameters.length; i++) {
// let regex = new RegExp(`\\$${i + 1}`, "g")
// query = query.replace(regex, `'${parameters[i]}'`)
// }

console.log("connection:", connection)
console.log("query:", query)
console.log("parameters:", parameters)
Expand Down

0 comments on commit a3a41c9

Please sign in to comment.