From 3e11b4aa74f06e24da0b6228da05c6778836a10e Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Mon, 7 Oct 2024 10:59:55 +0200 Subject: [PATCH] :sparkles: Add facility for wrap a rpc method in a db transaction --- backend/src/app/rpc.clj | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/backend/src/app/rpc.clj b/backend/src/app/rpc.clj index b51f2cde1..444cf4352 100644 --- a/backend/src/app/rpc.clj +++ b/backend/src/app/rpc.clj @@ -149,6 +149,13 @@ :hint "authentication required for this endpoint") (f cfg params))))) +(defn- wrap-db-transaction + [_ f mdata] + (if (::db/transaction mdata) + (fn [cfg params] + (db/tx-run! cfg f params)) + f)) + (defn- wrap-audit [_ f mdata] (if (or (contains? cf/flags :webhooks) @@ -196,6 +203,7 @@ (defn- wrap-all [cfg f mdata] (as-> f $ + (wrap-db-transaction cfg $ mdata) (cond/wrap cfg $ mdata) (retry/wrap-retry cfg $ mdata) (climit/wrap cfg $ mdata)