mirror of
https://github.com/penpot/penpot.git
synced 2026-08-23 05:08:53 +00:00
A projected graph is a cache of one file at one revision, built by one schema, and nothing in it said so. `GraphMeta` records the file, the revision, the schema version and the producer, and is written last, so its presence also marks the build complete and its contents say whether a cached database is still worth opening. - `graph/meta.clj`: the `GraphMeta` table and its writer. - `graph/schema/contract.clj`: one place that maps a Penpot key to its graph column. The rule is snake_case of the key; every exception, be it a rename, a drop or a type override, is recorded there with its reason, so a divergence is a diff to review rather than a silent rename. - `graph/project/document.clj`: `page-id` and the inherited `component-id` are written during the tree walk, which already knows both, rather than by a post-ingest statement. `graph/sync.clj` does the same on the incremental path, so a live-synced graph matches a rebuild. - `graph/project/transforms.clj`: a registry, so adding a derived-link pass is one entry. Adds `RefersTo` (from `shape-ref`) and `FillsSwapSlot` (from `swap-slot-*` entries in `touched`, then stripped as `ctk/normal-touched-groups` does). - `graph/debug.clj`, `graph/stats.clj`: enumerate relationship tables from the catalog instead of naming them, so the console's graph view and the ingest counts pick up new edge types without being told. - `graph/debug.clj`, `http/debug.clj`: `graph-export` gains `source=session`, which snapshots the live in-memory console graph through EXPORT/IMPORT DATABASE. Live sync moves that graph away from a fresh projection, and taking it away to query elsewhere is the point of asking for it. AI-assisted-by: mixed models
60 lines
2.1 KiB
Clojure
60 lines
2.1 KiB
Clojure
;; This Source Code Form is subject to the terms of the Mozilla Public
|
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
;;
|
|
;; Copyright (c) KALEIDOS INC Sucursal en España SL
|
|
|
|
(ns app.graph.meta
|
|
"`GraphMeta`: the graph's own account of who built it and from what.
|
|
|
|
A projected graph is a cache of a file at a revision, built by a known
|
|
schema. The row records both, so a reader can decide whether to reuse the
|
|
database or rebuild it: a `schema_version` that no longer matches the
|
|
registry, or a `source_revn` behind the file's, means the cache is stale.
|
|
|
|
The row is written *last* in a build, so its presence also marks the build
|
|
complete.
|
|
|
|
Keyed by `source_file_id` rather than holding a single row: a closure graph
|
|
is a union of per-file builds, and each contributing file keeps its own
|
|
provenance."
|
|
(:require
|
|
[app.common.time :as ct]
|
|
[app.graph.ladybug :as ladybug]
|
|
[app.graph.schema.nodes :as nodes])
|
|
(:import
|
|
com.ladybugdb.Connection))
|
|
|
|
(set! *warn-on-reflection* true)
|
|
|
|
(def table
|
|
"GraphMeta")
|
|
|
|
(def producer
|
|
"penpot")
|
|
|
|
(def ddl
|
|
"DDL for the provenance table."
|
|
(str "CREATE NODE TABLE `" table "` ("
|
|
"`source_file_id` UUID, "
|
|
"`producer` STRING, "
|
|
"`producer_version` STRING, "
|
|
"`schema_version` STRING, "
|
|
"`source_revn` INT64, "
|
|
"`built_at` TIMESTAMP, "
|
|
"PRIMARY KEY (`source_file_id`));"))
|
|
|
|
(defn write!
|
|
"Record what this build produced for `file-id`."
|
|
[^Connection conn {:keys [file-id revn]}]
|
|
(ladybug/exec-on-connection! conn [ddl])
|
|
(ladybug/exec-on-connection!
|
|
conn
|
|
[(str "MERGE (m:`" table "` {source_file_id: " (ladybug/format-uuid file-id) "}) "
|
|
"SET m.producer = " (ladybug/format-string producer) ", "
|
|
"m.producer_version = " (ladybug/format-string (or (System/getenv "PENPOT_BUILD") "devenv")) ", "
|
|
"m.schema_version = " (ladybug/format-string nodes/schema-version) ", "
|
|
"m.source_revn = " (ladybug/format-int (or revn 0)) ", "
|
|
"m.built_at = " (ladybug/format-timestamp (ct/now)) ";")]))
|
|
|