mirror of
https://github.com/penpot/penpot.git
synced 2025-02-13 18:48:37 -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:
parent
371c78b1d3
commit
024cc88738
3 changed files with 17 additions and 2 deletions
|
@ -187,6 +187,9 @@
|
||||||
|
|
||||||
{:name "0059-mod-audit-log-table"
|
{:name "0059-mod-audit-log-table"
|
||||||
:fn (mg/resource "app/migrations/sql/0059-mod-audit-log-table.sql")}
|
: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")}
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
ALTER TABLE file_change
|
||||||
|
ALTER COLUMN data DROP NOT NULL;
|
|
@ -43,7 +43,6 @@
|
||||||
(proj/check-edition-permissions! conn profile-id project-id)
|
(proj/check-edition-permissions! conn profile-id project-id)
|
||||||
(create-file conn params)))
|
(create-file conn params)))
|
||||||
|
|
||||||
|
|
||||||
(defn create-file-role
|
(defn create-file-role
|
||||||
[conn {:keys [file-id profile-id role]}]
|
[conn {:keys [file-id profile-id role]}]
|
||||||
(let [params {:file-id file-id
|
(let [params {:file-id file-id
|
||||||
|
@ -274,10 +273,20 @@
|
||||||
(update-file (assoc cfg :conn conn)
|
(update-file (assoc cfg :conn conn)
|
||||||
(assoc params :file file)))))
|
(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
|
(defn- update-file
|
||||||
[{:keys [conn] :as cfg} {:keys [file changes changes-with-metadata session-id profile-id] :as params}]
|
[{:keys [conn] :as cfg} {:keys [file changes changes-with-metadata session-id profile-id] :as params}]
|
||||||
(when (> (:revn params)
|
(when (> (:revn params)
|
||||||
(:revn file))
|
(:revn file))
|
||||||
|
|
||||||
(ex/raise :type :validation
|
(ex/raise :type :validation
|
||||||
:code :revn-conflict
|
:code :revn-conflict
|
||||||
:hint "The incoming revision number is greater that stored version."
|
:hint "The incoming revision number is greater that stored version."
|
||||||
|
@ -304,7 +313,8 @@
|
||||||
:profile-id profile-id
|
:profile-id profile-id
|
||||||
:file-id (:id file)
|
:file-id (:id file)
|
||||||
:revn (:revn file)
|
:revn (:revn file)
|
||||||
:data (:data file)
|
:data (when (take-snapshot? file)
|
||||||
|
(:data file))
|
||||||
:changes (blob/encode changes)})
|
:changes (blob/encode changes)})
|
||||||
|
|
||||||
;; Update file
|
;; Update file
|
||||||
|
|
Loading…
Add table
Reference in a new issue