mirror of
https://github.com/penpot/penpot.git
synced 2025-05-11 05:46:38 +02:00
🐛 Remove file lock contention on media upload.
This commit is contained in:
parent
ebb745cc11
commit
fa573f8a24
1 changed files with 9 additions and 9 deletions
|
@ -38,7 +38,7 @@
|
||||||
;; --- Create File Media object (upload)
|
;; --- Create File Media object (upload)
|
||||||
|
|
||||||
(declare create-file-media-object)
|
(declare create-file-media-object)
|
||||||
(declare select-file-for-update)
|
(declare select-file)
|
||||||
|
|
||||||
(s/def ::content ::media/upload)
|
(s/def ::content ::media/upload)
|
||||||
(s/def ::is-local ::us/boolean)
|
(s/def ::is-local ::us/boolean)
|
||||||
|
@ -50,7 +50,7 @@
|
||||||
(sv/defmethod ::upload-file-media-object
|
(sv/defmethod ::upload-file-media-object
|
||||||
[{:keys [pool] :as cfg} {:keys [profile-id file-id] :as params}]
|
[{:keys [pool] :as cfg} {:keys [profile-id file-id] :as params}]
|
||||||
(db/with-atomic [conn pool]
|
(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))
|
(teams/check-edition-permissions! conn profile-id (:team-id file))
|
||||||
(-> (assoc cfg :conn conn)
|
(-> (assoc cfg :conn conn)
|
||||||
(create-file-media-object params)))))
|
(create-file-media-object params)))))
|
||||||
|
@ -138,7 +138,7 @@
|
||||||
(sv/defmethod ::create-file-media-object-from-url
|
(sv/defmethod ::create-file-media-object-from-url
|
||||||
[{:keys [pool storage] :as cfg} {:keys [profile-id file-id url name] :as params}]
|
[{:keys [pool storage] :as cfg} {:keys [profile-id file-id url name] :as params}]
|
||||||
(db/with-atomic [conn pool]
|
(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))
|
(teams/check-edition-permissions! conn profile-id (:team-id file))
|
||||||
(let [mobj (download-media cfg url)
|
(let [mobj (download-media cfg url)
|
||||||
content {:filename "tempfile"
|
content {:filename "tempfile"
|
||||||
|
@ -161,7 +161,7 @@
|
||||||
(sv/defmethod ::clone-file-media-object
|
(sv/defmethod ::clone-file-media-object
|
||||||
[{:keys [pool] :as cfg} {:keys [profile-id file-id] :as params}]
|
[{:keys [pool] :as cfg} {:keys [profile-id file-id] :as params}]
|
||||||
(db/with-atomic [conn pool]
|
(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))
|
(teams/check-edition-permissions! conn profile-id (:team-id file))
|
||||||
|
|
||||||
(-> (assoc cfg :conn conn)
|
(-> (assoc cfg :conn conn)
|
||||||
|
@ -184,17 +184,17 @@
|
||||||
|
|
||||||
;; --- HELPERS
|
;; --- HELPERS
|
||||||
|
|
||||||
(def ^:private sql:select-file-for-update
|
(def ^:private
|
||||||
|
sql:select-file
|
||||||
"select file.*,
|
"select file.*,
|
||||||
project.team_id as team_id
|
project.team_id as team_id
|
||||||
from file
|
from file
|
||||||
inner join project on (project.id = file.project_id)
|
inner join project on (project.id = file.project_id)
|
||||||
where file.id = ?
|
where file.id = ?")
|
||||||
for update of file")
|
|
||||||
|
|
||||||
(defn- select-file-for-update
|
(defn- select-file
|
||||||
[conn id]
|
[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
|
(when-not row
|
||||||
(ex/raise :type :not-found))
|
(ex/raise :type :not-found))
|
||||||
row))
|
row))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue