From cb34cfefe9356a611dc2c7d06d4f608fa5a8688f Mon Sep 17 00:00:00 2001 From: Stuart Corbishley Date: Thu, 27 Jul 2023 09:46:31 +0200 Subject: [PATCH 1/2] Don't add cast fragments if the search_term is nil --- lib/lightning/invocation.ex | 56 +++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/lib/lightning/invocation.ex b/lib/lightning/invocation.ex index d19ee18113..a79307eb47 100644 --- a/lib/lightning/invocation.ex +++ b/lib/lightning/invocation.ex @@ -381,35 +381,37 @@ defmodule Lightning.Invocation do end) end - def filter_run_body_and_logs_where(_search_term, search_fields) - when search_fields == [] do - dynamic(true) - end - - def filter_run_body_and_logs_where(search_term, search_fields) - when search_fields != [] do - Enum.reduce(search_fields, dynamic(false), fn - :log, query -> - dynamic( - [log_lines: l], - ^query or - fragment( - "cast(? as VARCHAR) ilike ?", - l.body, - ^"%#{search_term}%" - ) - ) + def filter_run_body_and_logs_where(search_term, search_fields) do + if is_nil(search_term) do + dynamic(true) + else + Enum.reduce(search_fields || [], dynamic(false), fn + :log, query -> + dynamic( + [log_lines: l], + ^query or + fragment( + "cast(? as VARCHAR) ilike ?", + l.body, + ^"%#{search_term}%" + ) + ) - :body, query -> - dynamic( - [input: i], - ^query or - fragment("cast(? as VARCHAR) ilike ?", i.body, ^"%#{search_term}%") - ) + :body, query -> + dynamic( + [input: i], + ^query or + fragment( + "cast(? as VARCHAR) ilike ?", + i.body, + ^"%#{search_term}%" + ) + ) - _, query -> - query - end) + _, query -> + query + end) + end end def list_work_orders_for_project_query( From e88180d86db7897cc0f6b7007e48b1caa5585860 Mon Sep 17 00:00:00 2001 From: Stuart Corbishley Date: Thu, 27 Jul 2023 10:09:25 +0200 Subject: [PATCH 2/2] Update CHANGELOG --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 20943cbda2..6ad12a8717 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,9 @@ and this project adheres to ### Changed +- Don't add cast fragments if the search_term is nil + [#968](https://github.com/OpenFn/Lightning/issues/968) + ### Fixed ## [v0.7.0-pre2] - 2023-07-26