Skip to content

Commit

Permalink
feat: use left join when selecting contact urn as there's a possibili…
Browse files Browse the repository at this point in the history
…ty for it to not exist
  • Loading branch information
helllllllder committed Jul 22, 2024
1 parent 86e4fac commit fe08c9b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion flowrun/storage/postgresql.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
else:
get_flowrun_by_uuid_sql = "SELECT fr.id, fr.uuid, fr.status, fr.org_id, fr.created_on, fr.modified_on, fr.exited_on, fr.responded, fr.results, fr.delete_reason, fr.exit_type, c.uuid AS contact_uuid, c.name AS contact_name, cu.identity AS contact_urn, f.uuid AS flow_uuid, f.name AS flow_name, proj.project_uuid AS project_uuid FROM flows_flowrun fr INNER JOIN contacts_contact c ON fr.contact_id = c.id INNER JOIN contacts_contacturn cu ON cu.id =( SELECT id from contacts_contacturn WHERE contact_id = c.id FETCH FIRST 1 ROWS ONLY) INNER JOIN flows_flow f ON fr.flow_id = f.id INNER JOIN internal_project proj ON fr.org_id = proj.org_ptr_id WHERE fr.uuid =(%s);"

list_flowrun_by_org_id_and_modified_on_sql = "SELECT fr.id, fr.uuid, fr.org_id, fr.status, fr.created_on, fr.modified_on, fr.exited_on, fr.responded, fr.results, fr.delete_reason, fr.exit_type, c.uuid AS contact_uuid, c.name AS contact_name, cu.identity AS contact_urn, f.uuid AS flow_uuid, f.name AS flow_name, o.proj_uuid AS project_uuid FROM flows_flowrun fr INNER JOIN contacts_contact c ON fr.contact_id = c.id INNER JOIN contacts_contacturn cu ON cu.id =( SELECT id from contacts_contacturn WHERE contact_id = c.id FETCH FIRST 1 ROWS ONLY) INNER JOIN flows_flow f ON fr.flow_id = f.id INNER JOIN orgs_org o ON fr.org_id = o.id WHERE fr.exited_on IS NOT null AND fr.org_id =(%s) AND fr.modified_on > (%s) ORDER BY fr.modified_on ASC, id ASC FETCH FIRST (%s) ROWS ONLY;"
list_flowrun_by_org_id_and_modified_on_sql = "SELECT fr.id, fr.uuid, fr.org_id, fr.status, fr.created_on, fr.modified_on, fr.exited_on, fr.responded, fr.results, fr.delete_reason, fr.exit_type, c.uuid AS contact_uuid, c.name AS contact_name, cu.identity AS contact_urn, f.uuid AS flow_uuid, f.name AS flow_name, o.proj_uuid AS project_uuid FROM flows_flowrun fr INNER JOIN contacts_contact c ON fr.contact_id = c.id LEFT JOIN contacts_contacturn cu ON cu.id =( SELECT id from contacts_contacturn WHERE contact_id = c.id FETCH FIRST 1 ROWS ONLY) INNER JOIN flows_flow f ON fr.flow_id = f.id INNER JOIN orgs_org o ON fr.org_id = o.id WHERE fr.exited_on IS NOT null AND fr.org_id =(%s) AND fr.modified_on > (%s) ORDER BY fr.modified_on ASC, id ASC FETCH FIRST (%s) ROWS ONLY;"


class FlowRunPostgreSQL(BaseRetrieveStorage):
Expand Down

0 comments on commit fe08c9b

Please sign in to comment.