From 6f3a08be0c07d31f24573182d17fefe45431dcd4 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 10 Feb 2021 11:46:17 +0100 Subject: [PATCH] :bug: Remove file lock contention on media upload. --- backend/src/app/rpc/mutations/media.clj | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/backend/src/app/rpc/mutations/media.clj b/backend/src/app/rpc/mutations/media.clj index b6b115d7c..0cc6b967e 100644 --- a/backend/src/app/rpc/mutations/media.clj +++ b/backend/src/app/rpc/mutations/media.clj @@ -38,7 +38,7 @@ ;; --- Create File Media object (upload) (declare create-file-media-object) -(declare select-file-for-update) +(declare select-file) (s/def ::content ::media/upload) (s/def ::is-local ::us/boolean) @@ -50,7 +50,7 @@ (sv/defmethod ::upload-file-media-object [{:keys [pool] :as cfg} {:keys [profile-id file-id] :as params}] (db/with-atomic [conn pool] - (let [file (select-file-for-update conn file-id)] + (let [file (select-file conn file-id)] (teams/check-edition-permissions! conn profile-id (:team-id file)) (-> (assoc cfg :conn conn) (create-file-media-object params))))) @@ -129,7 +129,7 @@ (sv/defmethod ::create-file-media-object-from-url [{:keys [pool storage] :as cfg} {:keys [profile-id file-id url name] :as params}] (db/with-atomic [conn pool] - (let [file (select-file-for-update conn file-id)] + (let [file (select-file conn file-id)] (teams/check-edition-permissions! conn profile-id (:team-id file)) (let [mobj (download-media cfg url) content {:filename "tempfile" @@ -152,7 +152,7 @@ (sv/defmethod ::clone-file-media-object [{:keys [pool] :as cfg} {:keys [profile-id file-id] :as params}] (db/with-atomic [conn pool] - (let [file (select-file-for-update conn file-id)] + (let [file (select-file conn file-id)] (teams/check-edition-permissions! conn profile-id (:team-id file)) (-> (assoc cfg :conn conn) @@ -175,17 +175,17 @@ ;; --- HELPERS -(def ^:private sql:select-file-for-update +(def ^:private + sql:select-file "select file.*, project.team_id as team_id from file inner join project on (project.id = file.project_id) - where file.id = ? - for update of file") + where file.id = ?") -(defn- select-file-for-update +(defn- select-file [conn id] - (let [row (db/exec-one! conn [sql:select-file-for-update id])] + (let [row (db/exec-one! conn [sql:select-file id])] (when-not row (ex/raise :type :not-found)) row))