0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-09 08:20:45 -05:00

Add page-changes query.

This commit is contained in:
Andrey Antukh 2020-04-16 11:09:55 +02:00 committed by Alonso Torres
parent f19a8e67e1
commit 517b50238e
3 changed files with 40 additions and 115 deletions

View file

@ -81,52 +81,38 @@
(p/then' decode-row)))
;; --- Query: Page Changes
;; --- Query: Project Page History (by Page ID)
(def ^:private
sql:page-changes
"select pc.id,
pc.created_at,
pc.changes,
pc.revn
from page_change as pc
where pc.page_id=$1
order by pc.revn asc
limit $2
offset $3")
;; (def ^:private sql:generic-page-history
;; "select pph.*
;; from project_page_history as pph
;; where pph.page_id = $2
;; and pph.version < $3
;; order by pph.version < desc")
;; (def ^:private sql:page-history
;; (str "with history as (" sql:generic-page-history ")"
;; " select * from history limit $4"))
(s/def ::skip ::us/integer)
(s/def ::limit ::us/integer)
;; (def ^:private sql:pinned-page-history
;; (str "with history as (" sql:generic-page-history ")"
;; " select * from history where pinned = true limit $4"))
(s/def ::page-changes
(s/keys :req-un [::profile-id ::id ::skip ::limit]))
;; (s/def ::page-id ::us/uuid)
;; (s/def ::max ::us/integer)
;; (s/def ::pinned ::us/boolean)
;; (s/def ::since ::us/integer)
(defn retrieve-page-changes
[conn id skip limit]
(-> (db/query conn [sql:page-changes id limit skip])
(p/then' #(mapv decode-row %))))
;; (s/def ::project-page-snapshots
;; (s/keys :req-un [::page-id ::user]
;; :opt-un [::max ::pinned ::since]))
(sq/defquery ::page-changes
[{:keys [profile-id id skip limit]}]
(when *assert*
(-> (db/query db/pool [sql:page-changes id limit skip])
(p/then' #(mapv decode-row %)))))
;; (defn retrieve-page-snapshots
;; [conn {:keys [page-id user since max pinned] :or {since Long/MAX_VALUE max 10}}]
;; (let [sql (-> (sql/from ["project_page_snapshots" "ph"])
;; (sql/select "ph.*")
;; (sql/where ["ph.user_id = ?" user]
;; ["ph.page_id = ?" page-id]
;; ["ph.version < ?" since]
;; (when pinned
;; ["ph.pinned = ?" true]))
;; (sql/order "ph.version desc")
;; (sql/limit max))]
;; (-> (db/query conn (sql/fmt sql))
;; (p/then (partial mapv decode-row)))))
;; (sq/defquery ::project-page-snapshots
;; [{:keys [page-id user] :as params}]
;; (db/with-atomic [conn db/pool]
;; (p/do! (retrieve-page conn {:id page-id :user user})
;; (retrieve-page-snapshots conn params))))
;; --- Helpers

View file

@ -15,14 +15,17 @@
[clojure.pprint :refer [pprint]]
[clojure.test :as test]
[clojure.java.io :as io]
[uxbox.common.pages :as cp]
[clojure.repl :refer :all]
[criterium.core :refer [quick-bench bench with-progress-reporting]]
[clj-kondo.core :as kondo]
[promesa.core :as p]
[promesa.exec :as px]
[uxbox.migrations]
[uxbox.db :as db]
[uxbox.util.storage :as st]
[uxbox.util.time :as tm]
[uxbox.util.blob :as blob]
[mount.core :as mount]))
;; --- Benchmarking Tools
@ -86,80 +89,16 @@
'(promesa.core/let)]}}}})
(kondo/print!))))
(comment
{:version 1
:options {}
:shapes [:id1 :id2]
:canvas [:id3]
:shapes-by-id {:id1 {:canvas :id3} :id2 {} :id3 {}}})
;; (defn red
;; [items]
;; (as-> items $$
;; (reduce (fn [acc item]
;; (cp/process-changes acc (:changes item)))
;; cp/default-page-data
;; $$)))
(comment
{:version 2
:options {}
:objects
{:root
{:type :frame
:shapes [:sid0 :frame-0]}
:frame0
{:type :frame
:parent :root
:shapes [:sid1 :sid2]}
:sid0
{:type :rect
:parent :root}
:sid1
{:type :rect
:parent :frame0}
:sid2
{:type :group
:shapes [:sid3 :sid4]
:parent :frame0}
:sid3
{:type :elipse
:parent :sid2}
:sid4
{:type :elipse
:parent :sid2}}})
(comment
{:version 3
:options {}
:rmap
{:id1 :root-frame
:id2 :root-frame
:id3 :frame-id-1
:id4 :frame-id-2
:id5 :frame-id-2
:id6 :frame-id-2}
:frames
{:root-frame
{:type :frame
:shapes [:id1 :id2]
:objects
{:id1 {:type :rect}
:id2 {:type :elipse}}}
:frame-id-1
{:type :frame
:shapes [:id3]
:objects
{:id3 {:type :path}}}
:frame-id-2
{:type :frame
:shapes [:id4]
:objects
{:id4 {:type :group
:shapes [:id5 :id6]}
:id5 {:type :path :parent :id4}
:id6 {:type :elipse :parent :id4}}}}})
;; (defn update-page-data
;; [id data]
;; (let [data (blob/encode data)]
;; (db/query-one db/pool ["update page set data=$1 where id=$2" data id])))

View file

@ -134,5 +134,5 @@
(for [[i item] (d/enumerate childs)]
[:& shape-wrapper {:frame shape
:shape item
:key (str i (:id item))}])])))
:key (:id item)}])])))