0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-22 23:06:08 -05:00

💄 Remove neesting with ::db/transaction

This commit is contained in:
Andrey Antukh 2025-01-08 12:00:38 +01:00 committed by alonso.torres
parent 27c2db6cde
commit 1f4fafe781

View file

@ -238,7 +238,6 @@
{::doc/added "1.15" {::doc/added "1.15"
::sm/params schema:get-comment-threads} ::sm/params schema:get-comment-threads}
[cfg {:keys [::rpc/profile-id file-id share-id] :as params}] [cfg {:keys [::rpc/profile-id file-id share-id] :as params}]
(db/run! cfg (fn [{:keys [::db/conn]}] (db/run! cfg (fn [{:keys [::db/conn]}]
(files/check-comment-permissions! conn profile-id file-id share-id) (files/check-comment-permissions! conn profile-id file-id share-id)
(get-comment-threads conn profile-id file-id)))) (get-comment-threads conn profile-id file-id))))
@ -474,8 +473,7 @@
::rtry/enabled true ::rtry/enabled true
::rtry/when rtry/conflict-exception? ::rtry/when rtry/conflict-exception?
::sm/params schema:create-comment-thread} ::sm/params schema:create-comment-thread}
[cfg [cfg {:keys [::rpc/profile-id ::rpc/request-at file-id page-id share-id mentions position content frame-id]}]
{:keys [::rpc/profile-id ::rpc/request-at file-id page-id share-id mentions position content frame-id]}]
(files/check-comment-permissions! cfg profile-id file-id share-id) (files/check-comment-permissions! cfg profile-id file-id share-id)
(let [{:keys [team-id project-id page-name name]} (get-file cfg file-id page-id)] (let [{:keys [team-id project-id page-name name]} (get-file cfg file-id page-id)]
@ -569,12 +567,12 @@
(sv/defmethod ::update-comment-thread-status (sv/defmethod ::update-comment-thread-status
{::doc/added "1.15" {::doc/added "1.15"
::sm/params schema:update-comment-thread-status} ::sm/params schema:update-comment-thread-status
[cfg {:keys [::rpc/profile-id id share-id]}] ::db/transaction true}
(db/tx-run! cfg (fn [{:keys [::db/conn]}] [{:keys [::db/conn]} {:keys [::rpc/profile-id id share-id]}]
(let [{:keys [file-id] :as thread} (get-comment-thread conn id ::sql/for-update true)] (let [{:keys [file-id] :as thread} (get-comment-thread conn id ::sql/for-update true)]
(files/check-comment-permissions! conn profile-id file-id share-id) (files/check-comment-permissions! conn profile-id file-id share-id)
(upsert-comment-thread-status! conn profile-id id))))) (upsert-comment-thread-status! conn profile-id id)))
;; --- COMMAND: Update Comment Thread ;; --- COMMAND: Update Comment Thread
@ -587,16 +585,15 @@
(sv/defmethod ::update-comment-thread (sv/defmethod ::update-comment-thread
{::doc/added "1.15" {::doc/added "1.15"
::sm/params schema:update-comment-thread} ::sm/params schema:update-comment-thread
[cfg {:keys [::rpc/profile-id id is-resolved share-id]}] ::db/transaction true}
(db/tx-run! cfg (fn [{:keys [::db/conn]}] [{:keys [::db/conn]} {:keys [::rpc/profile-id id is-resolved share-id]}]
(let [{:keys [file-id] :as thread} (get-comment-thread conn id ::sql/for-update true)] (let [{:keys [file-id] :as thread} (get-comment-thread conn id ::sql/for-update true)]
(files/check-comment-permissions! conn profile-id file-id share-id) (files/check-comment-permissions! conn profile-id file-id share-id)
(db/update! conn :comment-thread (db/update! conn :comment-thread
{:is-resolved is-resolved} {:is-resolved is-resolved}
{:id id}) {:id id})
nil)))) nil))
;; --- COMMAND: Add Comment ;; --- COMMAND: Add Comment
@ -613,11 +610,9 @@
(sv/defmethod ::create-comment (sv/defmethod ::create-comment
{::doc/added "1.15" {::doc/added "1.15"
::webhooks/event? true ::webhooks/event? true
::sm/params schema:create-comment} ::sm/params schema:create-comment
[cfg {:keys [::rpc/profile-id ::rpc/request-at thread-id share-id content mentions]}] ::db/transaction true}
(db/tx-run! [{:keys [::db/conn] :as cfg} {:keys [::rpc/profile-id ::rpc/request-at thread-id share-id content mentions]}]
cfg
(fn [{:keys [::db/conn] :as cfg}]
(let [{:keys [file-id page-id] :as thread} (get-comment-thread conn thread-id ::sql/for-update true) (let [{:keys [file-id page-id] :as thread} (get-comment-thread conn thread-id ::sql/for-update true)
{file-name :name :keys [team-id project-id page-name] :as file} (get-file cfg file-id page-id)] {file-name :name :keys [team-id project-id page-name] :as file} (get-file cfg file-id page-id)]
@ -676,7 +671,7 @@
:page-name page-name}] :page-name page-name}]
(send-comment-emails! conn params comment thread)) (send-comment-emails! conn params comment thread))
(vary-meta comment assoc ::audit/props props)))))) (vary-meta comment assoc ::audit/props props))))
;; --- COMMAND: Update Comment ;; --- COMMAND: Update Comment
@ -691,10 +686,9 @@
;; TODO Check if there are new mentions, if there are send the new emails. ;; TODO Check if there are new mentions, if there are send the new emails.
(sv/defmethod ::update-comment (sv/defmethod ::update-comment
{::doc/added "1.15" {::doc/added "1.15"
::sm/params schema:update-comment} ::sm/params schema:update-comment
[cfg {:keys [::rpc/profile-id ::rpc/request-at id share-id content mentions]}] ::db/transaction true}
(db/tx-run! cfg [{:keys [::db/conn] :as cfg} {:keys [::rpc/profile-id ::rpc/request-at id share-id content mentions]}]
(fn [{:keys [::db/conn] :as cfg}]
(let [{:keys [thread-id owner-id] :as comment} (get-comment conn id ::sql/for-update true) (let [{:keys [thread-id owner-id] :as comment} (get-comment conn id ::sql/for-update true)
{:keys [file-id page-id] :as thread} (get-comment-thread conn thread-id ::sql/for-update true)] {:keys [file-id page-id] :as thread} (get-comment-thread conn thread-id ::sql/for-update true)]
@ -721,7 +715,7 @@
(into mentions) (into mentions)
(db/encode-pgarray conn "uuid"))} (db/encode-pgarray conn "uuid"))}
{:id thread-id}) {:id thread-id})
nil))))) nil)))
;; --- COMMAND: Delete Comment Thread ;; --- COMMAND: Delete Comment Thread
@ -733,9 +727,9 @@
(sv/defmethod ::delete-comment-thread (sv/defmethod ::delete-comment-thread
{::doc/added "1.15" {::doc/added "1.15"
::sm/params schema:delete-comment-thread} ::sm/params schema:delete-comment-thread
[cfg {:keys [::rpc/profile-id id share-id]}] ::db/transaction true}
(db/tx-run! cfg (fn [{:keys [::db/conn]}] [{:keys [::db/conn]} {:keys [::rpc/profile-id id share-id]}]
(let [{:keys [owner-id file-id] :as thread} (get-comment-thread conn id ::sql/for-update true)] (let [{:keys [owner-id file-id] :as thread} (get-comment-thread conn id ::sql/for-update true)]
(files/check-comment-permissions! conn profile-id file-id share-id) (files/check-comment-permissions! conn profile-id file-id share-id)
(when-not (= owner-id profile-id) (when-not (= owner-id profile-id)
@ -743,7 +737,7 @@
:code :not-allowed)) :code :not-allowed))
(db/delete! conn :comment-thread {:id id}) (db/delete! conn :comment-thread {:id id})
nil)))) nil))
;; --- COMMAND: Delete comment ;; --- COMMAND: Delete comment
@ -755,9 +749,9 @@
(sv/defmethod ::delete-comment (sv/defmethod ::delete-comment
{::doc/added "1.15" {::doc/added "1.15"
::sm/params schema:delete-comment} ::sm/params schema:delete-comment
[cfg {:keys [::rpc/profile-id id share-id]}] ::db/transaction true}
(db/tx-run! cfg (fn [{:keys [::db/conn]}] [{:keys [::db/conn]} {:keys [::rpc/profile-id id share-id]}]
(let [{:keys [owner-id thread-id] :as comment} (get-comment conn id ::sql/for-update true) (let [{:keys [owner-id thread-id] :as comment} (get-comment conn id ::sql/for-update true)
{:keys [file-id] :as thread} (get-comment-thread conn thread-id)] {:keys [file-id] :as thread} (get-comment-thread conn thread-id)]
(files/check-comment-permissions! conn profile-id file-id share-id) (files/check-comment-permissions! conn profile-id file-id share-id)
@ -765,7 +759,7 @@
(ex/raise :type :validation (ex/raise :type :validation
:code :not-allowed)) :code :not-allowed))
(db/delete! conn :comment {:id id}) (db/delete! conn :comment {:id id})
nil)))) nil))
;; --- COMMAND: Update comment thread position ;; --- COMMAND: Update comment thread position
@ -779,9 +773,9 @@
(sv/defmethod ::update-comment-thread-position (sv/defmethod ::update-comment-thread-position
{::doc/added "1.15" {::doc/added "1.15"
::sm/params schema:update-comment-thread-position} ::sm/params schema:update-comment-thread-position
[cfg {:keys [::rpc/profile-id ::rpc/request-at id position frame-id share-id]}] ::db/transaction true}
(db/tx-run! cfg (fn [{:keys [::db/conn]}] [{:keys [::db/conn]} {:keys [::rpc/profile-id ::rpc/request-at id position frame-id share-id]}]
(let [{:keys [file-id] :as thread} (get-comment-thread conn id ::sql/for-update true)] (let [{:keys [file-id] :as thread} (get-comment-thread conn id ::sql/for-update true)]
(files/check-comment-permissions! conn profile-id file-id share-id) (files/check-comment-permissions! conn profile-id file-id share-id)
(db/update! conn :comment-thread (db/update! conn :comment-thread
@ -789,7 +783,7 @@
:position (db/pgpoint position) :position (db/pgpoint position)
:frame-id frame-id} :frame-id frame-id}
{:id (:id thread)}) {:id (:id thread)})
nil)))) nil))
;; --- COMMAND: Update comment frame ;; --- COMMAND: Update comment frame
@ -802,13 +796,13 @@
(sv/defmethod ::update-comment-thread-frame (sv/defmethod ::update-comment-thread-frame
{::doc/added "1.15" {::doc/added "1.15"
::sm/params schema:update-comment-thread-frame} ::sm/params schema:update-comment-thread-frame
[cfg {:keys [::rpc/profile-id ::rpc/request-at id frame-id share-id]}] ::db/transaction true}
(db/tx-run! cfg (fn [{:keys [::db/conn]}] [{:keys [::db/conn]} {:keys [::rpc/profile-id ::rpc/request-at id frame-id share-id]}]
(let [{:keys [file-id] :as thread} (get-comment-thread conn id ::sql/for-update true)] (let [{:keys [file-id] :as thread} (get-comment-thread conn id ::sql/for-update true)]
(files/check-comment-permissions! conn profile-id file-id share-id) (files/check-comment-permissions! conn profile-id file-id share-id)
(db/update! conn :comment-thread (db/update! conn :comment-thread
{:modified-at request-at {:modified-at request-at
:frame-id frame-id} :frame-id frame-id}
{:id id}) {:id id})
nil)))) nil))