0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-10 00:58:26 -05:00

Reduce the file-change snapshot taking ratio.

Until now, a file `data` snapshot was persisted on every file_change
row. That causes a lot of IO load and increase disk usage without
a real benefit.

This commit reduces the snapshot generation; now the snapshot
is persisted every 20 update-file or when a file is not touched
in 3 hours or more.
This commit is contained in:
Andrey Antukh 2021-06-10 15:37:56 +02:00 committed by Alonso Torres
parent 371c78b1d3
commit 024cc88738
3 changed files with 17 additions and 2 deletions

View file

@ -187,6 +187,9 @@
{:name "0059-mod-audit-log-table"
:fn (mg/resource "app/migrations/sql/0059-mod-audit-log-table.sql")}
{:name "0060-mod-file-change-table"
:fn (mg/resource "app/migrations/sql/0060-mod-file-change-table.sql")}
])

View file

@ -0,0 +1,2 @@
ALTER TABLE file_change
ALTER COLUMN data DROP NOT NULL;

View file

@ -43,7 +43,6 @@
(proj/check-edition-permissions! conn profile-id project-id)
(create-file conn params)))
(defn create-file-role
[conn {:keys [file-id profile-id role]}]
(let [params {:file-id file-id
@ -274,10 +273,20 @@
(update-file (assoc cfg :conn conn)
(assoc params :file file)))))
(defn- take-snapshot?
"Defines the rule when file `data` snapshot should be saved."
[{: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})))))
(defn- update-file
[{:keys [conn] :as cfg} {:keys [file changes changes-with-metadata session-id profile-id] :as params}]
(when (> (:revn params)
(:revn file))
(ex/raise :type :validation
:code :revn-conflict
:hint "The incoming revision number is greater that stored version."
@ -304,7 +313,8 @@
:profile-id profile-id
:file-id (:id file)
:revn (:revn file)
:data (:data file)
:data (when (take-snapshot? file)
(:data file))
:changes (blob/encode changes)})
;; Update file