|
5 | 5 | TOOLBOX_APP_KEY, |
6 | 6 | } from '@/apps/toolbox/common/constants' |
7 | 7 | import paginate from '@/helpers/pagination' |
| 8 | +import ExecutionStep from '@/models/execution-step' |
8 | 9 |
|
9 | 10 | import type { QueryResolvers } from '../__generated__/types.generated' |
10 | 11 |
|
@@ -55,60 +56,16 @@ const getExecutionSteps: QueryResolvers['getExecutionSteps'] = async ( |
55 | 56 | // NOTE: use a separate query for for-each |
56 | 57 | // as there are multiple execution steps with the same step_id in the same execution |
57 | 58 | if (hasForEach) { |
58 | | - const forEachExecutionSteps = execution |
59 | | - .$relatedQuery('executionSteps') |
60 | | - .with('latest_steps', (builder) => { |
61 | | - /** |
62 | | - * NOTE: there is a known issue with knex where 'groupBy' are placed at the end of the 'unionAll' query. |
63 | | - * the workaround is to unionAll both queries with 'true' to wrap the subequery. |
64 | | - */ |
65 | | - builder |
66 | | - .unionAll((qb) => { |
67 | | - qb.select( |
68 | | - 'step_id', |
69 | | - raw('max(created_at) as max_created_at'), |
70 | | - raw('min(created_at) as min_created_at'), |
71 | | - ) |
72 | | - .from('execution_steps') |
73 | | - .groupBy('step_id') |
74 | | - .where('execution_id', '=', execution.id) |
75 | | - .where(raw("metadata = '{}'::jsonb")) |
76 | | - .withSoftDeleted() |
77 | | - }, true) |
78 | | - .unionAll((qb) => { |
79 | | - qb.select( |
80 | | - 'step_id', |
81 | | - raw('max(created_at) as max_created_at'), |
82 | | - raw('min(created_at) as min_created_at'), |
83 | | - ) |
84 | | - .from('execution_steps') |
85 | | - .groupBy('step_id', raw("metadata->>'iteration'")) |
86 | | - .where('execution_id', '=', execution.id) |
87 | | - .where(raw("metadata != '{}'::jsonb")) |
88 | | - .withSoftDeleted() |
89 | | - }, true) |
90 | | - .withSoftDeleted() |
91 | | - }) |
92 | | - .join('latest_steps', (builder) => { |
93 | | - builder |
94 | | - .on('execution_steps.step_id', '=', 'latest_steps.step_id') |
95 | | - .andOn( |
96 | | - 'execution_steps.created_at', |
97 | | - '=', |
98 | | - 'latest_steps.max_created_at', |
99 | | - ) |
100 | | - }) |
101 | | - .select('execution_steps.*', 'min_created_at') |
102 | | - .withSoftDeleted() |
103 | | - .orderBy('min_created_at', 'asc') |
| 59 | + const forEachExecutionSteps = await ExecutionStep.getForEachExecutionSteps( |
| 60 | + execution.id, |
| 61 | + ) |
104 | 62 |
|
105 | | - const allRecords = await forEachExecutionSteps |
106 | 63 | return { |
107 | 64 | pageInfo: { |
108 | 65 | currentPage: 1, |
109 | 66 | totalCount: 100, |
110 | 67 | }, |
111 | | - edges: allRecords.map((record) => ({ |
| 68 | + edges: forEachExecutionSteps.map((record) => ({ |
112 | 69 | node: record, |
113 | 70 | })), |
114 | 71 | } |
|
0 commit comments