mirror of
https://github.com/penpot/penpot.git
synced 2025-01-22 22:49:01 -05:00
🐛 Remove duplicate work on storing already existing files in storage
This commit is contained in:
parent
0bbd898173
commit
3a55f07f45
1 changed files with 17 additions and 13 deletions
|
@ -84,13 +84,14 @@
|
||||||
" and backend = ?"
|
" and backend = ?"
|
||||||
" and deleted_at is null"
|
" and deleted_at is null"
|
||||||
" limit 1")]
|
" limit 1")]
|
||||||
(db/exec-one! conn [sql hash bucket (name backend)])))
|
(some-> (db/exec-one! conn [sql hash bucket (name backend)])
|
||||||
|
(update :metadata db/decode-transit-pgobject))))
|
||||||
|
|
||||||
(defn- create-database-object
|
(defn- create-database-object
|
||||||
[{:keys [conn backend executor]} {:keys [::content ::expired-at ::touched-at] :as params}]
|
[{:keys [conn backend executor]} {:keys [::content ::expired-at ::touched-at] :as params}]
|
||||||
(us/assert ::storage-content content)
|
(us/assert ::storage-content content)
|
||||||
(px/with-dispatch executor
|
(px/with-dispatch executor
|
||||||
(let [id (uuid/random)
|
(let [id (uuid/next)
|
||||||
|
|
||||||
mdata (cond-> (get-metadata params)
|
mdata (cond-> (get-metadata params)
|
||||||
(satisfies? impl/IContentHash content)
|
(satisfies? impl/IContentHash content)
|
||||||
|
@ -106,13 +107,15 @@
|
||||||
(get-database-object-by-hash conn backend (:bucket mdata) (:hash mdata)))
|
(get-database-object-by-hash conn backend (:bucket mdata) (:hash mdata)))
|
||||||
|
|
||||||
result (or result
|
result (or result
|
||||||
(db/insert! conn :storage-object
|
(-> (db/insert! conn :storage-object
|
||||||
{:id id
|
{:id id
|
||||||
:size (count content)
|
:size (count content)
|
||||||
:backend (name backend)
|
:backend (name backend)
|
||||||
:metadata (db/tjson mdata)
|
:metadata (db/tjson mdata)
|
||||||
:deleted-at expired-at
|
:deleted-at expired-at
|
||||||
:touched-at touched-at}))]
|
:touched-at touched-at})
|
||||||
|
(update :metadata db/decode-transit-pgobject)
|
||||||
|
(update :metadata assoc ::created? true)))]
|
||||||
|
|
||||||
(StorageObject. (:id result)
|
(StorageObject. (:id result)
|
||||||
(:size result)
|
(:size result)
|
||||||
|
@ -120,7 +123,7 @@
|
||||||
(:deleted-at result)
|
(:deleted-at result)
|
||||||
(:touched-at result)
|
(:touched-at result)
|
||||||
backend
|
backend
|
||||||
mdata
|
(:metadata result)
|
||||||
nil))))
|
nil))))
|
||||||
|
|
||||||
(def ^:private sql:retrieve-storage-object
|
(def ^:private sql:retrieve-storage-object
|
||||||
|
@ -173,9 +176,10 @@
|
||||||
(p/let [storage (assoc storage :conn (or conn pool))
|
(p/let [storage (assoc storage :conn (or conn pool))
|
||||||
object (create-database-object storage params)]
|
object (create-database-object storage params)]
|
||||||
|
|
||||||
;; Store the data finally on the underlying storage subsystem.
|
(when (::created? (meta object))
|
||||||
(-> (impl/resolve-backend storage backend)
|
;; Store the data finally on the underlying storage subsystem.
|
||||||
(impl/put-object object content))
|
(-> (impl/resolve-backend storage backend)
|
||||||
|
(impl/put-object object content)))
|
||||||
|
|
||||||
object))
|
object))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue