mirror of
https://github.com/penpot/penpot.git
synced 2025-12-11 22:14:05 +01:00
♻️ Refactor cocurrency model on backend
Mainly the followin changes: - Pass majority of code to the old and plain synchronous style and start using virtual threads for the RPC (and partially some HTTP server middlewares). - Make some improvements on how CLIMIT is handled, simplifying code - Improve considerably performance reducing the reflection and unnecesary funcion calls on the whole stack-trace of an RPC call. - Improve efficiency reducing considerably the total threads number.
This commit is contained in:
@@ -138,9 +138,7 @@
|
||||
:app.http.oauth/handler
|
||||
:app.notifications/handler
|
||||
:app.loggers.mattermost/reporter
|
||||
:app.loggers.loki/reporter
|
||||
:app.loggers.database/reporter
|
||||
:app.loggers.zmq/receiver
|
||||
:app.worker/cron
|
||||
:app.worker/worker))
|
||||
_ (ig/load-namespaces system)
|
||||
@@ -164,11 +162,15 @@
|
||||
" AND table_name != 'migrations';")]
|
||||
(db/with-atomic [conn *pool*]
|
||||
(let [result (->> (db/exec! conn [sql])
|
||||
(map :table-name))]
|
||||
(db/exec! conn [(str "TRUNCATE "
|
||||
(apply str (interpose ", " result))
|
||||
" CASCADE;")]))))
|
||||
(next))
|
||||
(map :table-name)
|
||||
(remove #(= "task" %)))
|
||||
sql (str "TRUNCATE "
|
||||
(apply str (interpose ", " result))
|
||||
" CASCADE;")]
|
||||
(doseq [table result]
|
||||
(db/exec! conn [(str "delete from " table ";")]))))
|
||||
|
||||
(next)))
|
||||
|
||||
(defn clean-storage
|
||||
[next]
|
||||
@@ -321,7 +323,7 @@
|
||||
(with-open [conn (db/open pool)]
|
||||
(let [features #{"components/v2"}
|
||||
cfg (-> (select-keys *system* [::mbus/msgbus ::mtx/metrics])
|
||||
(assoc :conn conn))]
|
||||
(assoc ::db/conn conn))]
|
||||
(files.update/update-file cfg
|
||||
{:id file-id
|
||||
:revn revn
|
||||
@@ -354,7 +356,7 @@
|
||||
(defmacro try-on!
|
||||
[expr]
|
||||
`(try
|
||||
(let [result# (deref ~expr)
|
||||
(let [result# ~expr
|
||||
result# (cond-> result# (rph/wrapped? result#) deref)]
|
||||
{:error nil
|
||||
:result result#})
|
||||
@@ -364,7 +366,7 @@
|
||||
|
||||
(defn command!
|
||||
[{:keys [::type] :as data}]
|
||||
(let [method-fn (get-in *system* [:app.rpc/methods :commands type])]
|
||||
(let [[mdata method-fn] (get-in *system* [:app.rpc/methods :commands type])]
|
||||
(when-not method-fn
|
||||
(ex/raise :type :assertion
|
||||
:code :rpc-method-not-found
|
||||
@@ -377,7 +379,7 @@
|
||||
|
||||
(defn mutation!
|
||||
[{:keys [::type profile-id] :as data}]
|
||||
(let [method-fn (get-in *system* [:app.rpc/methods :mutations type])]
|
||||
(let [[mdata method-fn] (get-in *system* [:app.rpc/methods :mutations type])]
|
||||
(try-on! (method-fn (-> data
|
||||
(dissoc ::type)
|
||||
(assoc ::rpc/profile-id profile-id)
|
||||
@@ -385,7 +387,7 @@
|
||||
|
||||
(defn query!
|
||||
[{:keys [::type profile-id] :as data}]
|
||||
(let [method-fn (get-in *system* [:app.rpc/methods :queries type])]
|
||||
(let [[mdata method-fn] (get-in *system* [:app.rpc/methods :queries type])]
|
||||
(try-on! (method-fn (-> data
|
||||
(dissoc ::type)
|
||||
(assoc ::rpc/profile-id profile-id)
|
||||
|
||||
@@ -40,6 +40,6 @@
|
||||
{:keys [error result]} (th/command! (assoc params ::cond/key etag))]
|
||||
(t/is (nil? error))
|
||||
(t/is (fn? result))
|
||||
(t/is (= 304 (-> (result nil) :status))))
|
||||
(t/is (= 304 (-> (result nil) :yetti.response/status))))
|
||||
))))
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
(ns backend-tests.rpc-team-test
|
||||
(:require
|
||||
[app.common.logging :as l]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.db :as db]
|
||||
[app.http :as http]
|
||||
|
||||
Reference in New Issue
Block a user