File tree Expand file tree Collapse file tree
openleadr-vtn/src/data_source/postgres Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -215,18 +215,8 @@ impl Crud for PgEventStorage {
215215 SELECT e.*
216216 FROM event e
217217 JOIN program p on p.id = e.program_id
218- LEFT JOIN LATERAL (
219-
220- SELECT targets.e_id,
221- (t ?| $2) AS target_test
222- FROM (SELECT event.id AS e_id,
223- event.targets AS t
224- FROM event) AS targets
225-
226- )
227- ON e.id = e_id
228218 WHERE ($1::text IS NULL OR e.program_id like $1)
229- AND ($2 IS NULL OR target_test )
219+ AND ($2::text[] IS NULL OR e.targets ?| $2 )
230220 AND ($3 AND ($4::text[] IS NULL OR p.business_id = ANY ($4)))
231221 GROUP BY e.id, e.priority, e.created_date_time
232222 ORDER BY priority ASC , created_date_time DESC
Original file line number Diff line number Diff line change @@ -259,17 +259,7 @@ impl Crud for PgProgramStorage {
259259 p.payload_descriptors,
260260 p.targets
261261 FROM program p
262- LEFT JOIN LATERAL (
263-
264- SELECT targets.p_id,
265- (t ?| $1) AS target_test
266- FROM (SELECT program.id AS p_id,
267- program.targets AS t
268- FROM program) AS targets
269-
270- )
271- ON p.id = p_id
272- WHERE ($1 IS NULL OR target_test)
262+ WHERE ($1::text[] IS NULL OR p.targets ?| $1)
273263 GROUP BY p.id, p.created_date_time
274264 ORDER BY p.created_date_time DESC
275265 OFFSET $2 LIMIT $3
Original file line number Diff line number Diff line change @@ -166,19 +166,9 @@ impl VenScopedCrud for PgResourceStorage {
166166 r.attributes,
167167 r.targets
168168 FROM resource r
169- LEFT JOIN LATERAL (
170-
171- SELECT targets.r_id,
172- (t ?| $3) AS target_test
173- FROM (SELECT resource.id AS r_id,
174- resource.targets AS t
175- FROM resource) AS targets
176-
177- )
178- ON r.id = r_id
179169 WHERE r.ven_id = $1
180170 AND ($2::text IS NULL OR r.resource_name = $2)
181- AND ($3 IS NULL OR target_test )
171+ AND ($3::text[] IS NULL OR r.targets ?| $3 )
182172 ORDER BY r.created_date_time
183173 OFFSET $4 LIMIT $5
184174 "# ,
Original file line number Diff line number Diff line change @@ -168,19 +168,8 @@ impl Crud for PgVenStorage {
168168 v.targets
169169 FROM ven v
170170 LEFT JOIN resource r ON r.ven_id = v.id
171- LEFT JOIN LATERAL (
172-
173- -- FIXME simplify
174- SELECT targets.v_id,
175- (t ?| $2) AS target_test
176- FROM (SELECT ven.id AS v_id,
177- ven.targets AS t
178- FROM ven) AS targets
179-
180- )
181- ON v.id = v_id
182171 WHERE ($1::text IS NULL OR v.ven_name = $1)
183- AND ($2 IS NULL OR target_test )
172+ AND ($2::text[] IS NULL OR v.targets ?| $2 )
184173 AND ($3::text[] IS NULL OR v.id = ANY($3))
185174 ORDER BY v.created_date_time DESC
186175 OFFSET $4 LIMIT $5
You can’t perform that action at this time.
0 commit comments