From 00b8969f45ad100400690044b9bcf7aeb5a671c3 Mon Sep 17 00:00:00 2001 From: Stephen Compall Date: Wed, 16 Jun 2021 18:38:01 -0400 Subject: [PATCH] join and query the contract_stakeholders table for party-set membership - restoring a few elements removed by 3e6661128d (#9484) --- .../digitalasset/http/dbbackend/Queries.scala | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/ledger-service/db-backend/src/main/scala/com/digitalasset/http/dbbackend/Queries.scala b/ledger-service/db-backend/src/main/scala/com/digitalasset/http/dbbackend/Queries.scala index ebc971c5af18..258748778599 100644 --- a/ledger-service/db-backend/src/main/scala/com/digitalasset/http/dbbackend/Queries.scala +++ b/ledger-service/db-backend/src/main/scala/com/digitalasset/http/dbbackend/Queries.scala @@ -693,16 +693,19 @@ private object OracleQueries extends Queries { fr" OR ", ) } - val quotedParties = parties.toVector.map(p => s""""$p"""").mkString(", ") - val partiesQuery = oracleShortPathEscape( - '$' -: ("[*]?(@ in (": Cord) :+ quotedParties :+ "))" - ) - val q = - sql"""SELECT c.contract_id contract_id, $tpid template_id, key, payload, signatories, observers, agreement_text + import Queries.CompatImplicits.catsReducibleFromFoldable1 + val outerSelectList = + sql"""contract_id, template_id, key, payload, + signatories, observers, agreement_text""" + val dupQ = + sql"""SELECT c.contract_id contract_id, $tpid template_id, key, payload, + signatories, observers, agreement_text, + row_number() over (PARTITION BY c.contract_id ORDER BY c.contract_id) AS rownumber FROM contract c - WHERE (JSON_EXISTS(signatories, $partiesQuery) - OR JSON_EXISTS(observers, $partiesQuery)) - AND $queriesCondition""" + LEFT JOIN contract_stakeholders cst ON (c.contract_id = cst.contract_id) + WHERE (${Fragments.in(fr"cst.stakeholder", parties)}) + AND ($queriesCondition)""" + val q = sql"SELECT $outerSelectList FROM ($dupQ) WHERE rownumber = 1" q.query[ (String, Mark0, JsValue, JsValue, JsValue, JsValue, Option[String]) ].map { case (cid, tpid, key, payload, signatories, observers, agreement) =>