mirror of
https://github.com/penpot/penpot.git
synced 2025-02-12 10:09:03 -05:00
🎉 Add better hashing approach for database locking on Uuids
This commit is contained in:
parent
38468d7584
commit
fad2e51cbe
3 changed files with 24 additions and 2 deletions
|
@ -30,6 +30,7 @@
|
|||
com.zaxxer/HikariCP {:mvn/version "5.0.1"}
|
||||
|
||||
funcool/datoteka {:mvn/version "3.0.64"}
|
||||
io.whitfin/siphash {:mvn/version "2.0.0"}
|
||||
|
||||
buddy/buddy-hashers {:mvn/version "1.8.158"}
|
||||
buddy/buddy-sign {:mvn/version "3.4.333"}
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
com.zaxxer.hikari.HikariConfig
|
||||
com.zaxxer.hikari.HikariDataSource
|
||||
com.zaxxer.hikari.metrics.prometheus.PrometheusMetricsTrackerFactory
|
||||
io.whitfin.siphash.SipHasher
|
||||
io.whitfin.siphash.SipHasherContainer
|
||||
java.io.InputStream
|
||||
java.io.OutputStream
|
||||
java.lang.AutoCloseable
|
||||
|
@ -431,10 +433,19 @@
|
|||
|
||||
;; --- Locks
|
||||
|
||||
(def ^:private siphash-state
|
||||
(SipHasher/container
|
||||
(uuid/get-bytes uuid/zero)))
|
||||
|
||||
(defn uuid->hash-code
|
||||
[o]
|
||||
(.hash ^SipHasherContainer siphash-state
|
||||
^bytes (uuid/get-bytes o)))
|
||||
|
||||
(defn- xact-check-param
|
||||
[n]
|
||||
(cond
|
||||
(uuid? n) (uuid/get-word-high n)
|
||||
(uuid? n) (uuid->hash-code n)
|
||||
(int? n) n
|
||||
:else (throw (IllegalArgumentException. "uuid or number allowed"))))
|
||||
|
||||
|
|
|
@ -12,7 +12,9 @@
|
|||
#?(:clj [clojure.core :as c])
|
||||
#?(:cljs [app.common.uuid-impl :as impl])
|
||||
#?(:cljs [cljs.core :as c]))
|
||||
#?(:clj (:import java.util.UUID)))
|
||||
#?(:clj (:import
|
||||
java.util.UUID
|
||||
java.nio.ByteBuffer)))
|
||||
|
||||
(def zero #uuid "00000000-0000-0000-0000-000000000000")
|
||||
|
||||
|
@ -51,3 +53,11 @@
|
|||
|
||||
#?(:clj
|
||||
(dm/export impl/get-word-low))
|
||||
|
||||
#?(:clj
|
||||
(defn get-bytes
|
||||
[^UUID o]
|
||||
(let [buf (ByteBuffer/allocate 16)]
|
||||
(.putLong buf (.getMostSignificantBits o))
|
||||
(.putLong buf (.getLeastSignificantBits o))
|
||||
(.array buf))))
|
||||
|
|
Loading…
Add table
Reference in a new issue