From 4928f875b33d4dce8af5ab007b1e7aadaa325449 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Thu, 10 Jun 2021 15:43:13 +0200 Subject: [PATCH] :sparkles: Strip incoming changes from update-file response. Until now, `update-file` always returned a ordered set of change-groups plus the one created by the ongoing request. A change-group corresponds to a list of changes commited in a single update-file (file_change table row). Including the ongoing request change-group on response with increase load stated causing considerable amount of memmory pressure. Since this changes are no longer necessary on frontend side, with this commit we strip the changes list from the ongoing request change-group, sending back an empty entry with the increased `revn` number. --- backend/src/app/rpc/mutations/files.clj | 32 ++++++++++++++----------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/backend/src/app/rpc/mutations/files.clj b/backend/src/app/rpc/mutations/files.clj index d89bd3874..a4f37867f 100644 --- a/backend/src/app/rpc/mutations/files.clj +++ b/backend/src/app/rpc/mutations/files.clj @@ -332,6 +332,24 @@ ;; Retrieve and return lagged data (retrieve-lagged-changes conn params)))) +(def ^:private + sql:lagged-changes + "select s.id, s.revn, s.file_id, + s.session_id, s.changes + from file_change as s + where s.file_id = ? + and s.revn > ? + order by s.created_at asc") + +(defn- retrieve-lagged-changes + [conn params] + (->> (db/exec! conn [sql:lagged-changes (:id params) (:revn params)]) + (into [] (comp (map files/decode-row) + (map (fn [row] + (cond-> row + (= (:revn row) (:revn (:file params))) + (assoc :changes [])))))))) + (defn- send-notifications [{:keys [msgbus conn] :as cfg} {:keys [file changes session-id] :as params}] (let [lchanges (filter library-change? changes)] @@ -363,17 +381,3 @@ [conn project-id] (:team-id (db/get-by-id conn :project project-id {:columns [:team-id]}))) -(def ^:private - sql:lagged-changes - "select s.id, s.revn, s.file_id, - s.session_id, s.changes - from file_change as s - where s.file_id = ? - and s.revn > ? - order by s.created_at asc") - -(defn- retrieve-lagged-changes - [conn params] - (->> (db/exec! conn [sql:lagged-changes (:id params) (:revn params)]) - (mapv files/decode-row))) -