From f24563503ae3af77efd32ab457238d9616e0dabb Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Thu, 30 Dec 2021 13:02:42 +0100 Subject: [PATCH] :sparkles: Parametrice file change snapshoting. --- backend/src/app/config.clj | 8 ++++++++ backend/src/app/rpc/mutations/files.clj | 11 ++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/backend/src/app/config.clj b/backend/src/app/config.clj index ba83d458e..c1c05cc8f 100644 --- a/backend/src/app/config.clj +++ b/backend/src/app/config.clj @@ -52,6 +52,9 @@ :default-blob-version 3 :loggers-zmq-uri "tcp://localhost:45556" + :file-change-snapshot-every 1 + :file-change-snapshot-timeout "3h" + :public-uri "http://localhost:3449" :redis-uri "redis://redis/0" @@ -99,6 +102,9 @@ (s/def ::audit-log-archive-uri ::us/string) (s/def ::audit-log-gc-max-age ::dt/duration) +(s/def ::file-change-snapshot-every ::us/integer) +(s/def ::file-change-snapshot-timeout ::dt/duration) + (s/def ::secret-key ::us/string) (s/def ::allow-demo-users ::us/boolean) (s/def ::assets-path ::us/string) @@ -195,6 +201,8 @@ ::database-username ::default-blob-version ::error-report-webhook + ::file-change-snapshot-every + ::file-change-snapshot-timeout ::user-feedback-destination ::github-client-id ::github-client-secret diff --git a/backend/src/app/rpc/mutations/files.clj b/backend/src/app/rpc/mutations/files.clj index d9dd5ff12..5d7d4888a 100644 --- a/backend/src/app/rpc/mutations/files.clj +++ b/backend/src/app/rpc/mutations/files.clj @@ -11,6 +11,7 @@ [app.common.pages.migrations :as pmg] [app.common.spec :as us] [app.common.uuid :as uuid] + [app.config :as cf] [app.db :as db] [app.metrics :as mtx] [app.rpc.permissions :as perms] @@ -282,9 +283,13 @@ [{:keys [revn modified-at] :as file}] ;; The snapshot will be saved every 20 changes or if the last ;; modification is older than 3 hour. - (or (zero? (mod revn 20)) - (> (inst-ms (dt/diff modified-at (dt/now))) - (inst-ms (dt/duration {:hours 3}))))) + (let [freq (or (cf/get :file-change-snapshot-every) 20) + timeout (or (cf/get :file-change-snapshot-timeout) + (dt/duration {:hours 1}))] + (or (= 1 freq) + (zero? (mod revn freq)) + (> (inst-ms (dt/diff modified-at (dt/now))) + (inst-ms timeout))))) (defn- delete-from-storage [{:keys [storage] :as cfg} file]