forked from logseq/logseq
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1760161
commit deb14ed
Showing
6 changed files
with
81 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
(ns frontend.worker.db.validate | ||
"Validate db" | ||
(:require [cljs.pprint :as pprint] | ||
[frontend.worker.util :as worker-util] | ||
[logseq.db :as ldb] | ||
[logseq.db.frontend.validate :as db-validate])) | ||
|
||
(defn- counts-from-entities | ||
[entities] | ||
{:entities (count entities) | ||
:pages (count (filter :block/name entities)) | ||
:blocks (count (filter :block/title entities)) | ||
:classes (count (filter ldb/class? entities)) | ||
:objects (count (filter #(seq (:block/tags %)) entities)) | ||
:properties (count (filter ldb/property? entities)) | ||
:property-values (count (mapcat :block/properties entities))}) | ||
|
||
(defn validate-db | ||
[db] | ||
(let [{:keys [errors datom-count entities]} (db-validate/validate-db! db)] | ||
(if errors | ||
(do | ||
(worker-util/post-message :log [:db-invalid :error | ||
{:msg (str "Validation detected " (count errors) " invalid block(s):") | ||
:counts (assoc (counts-from-entities entities) :datoms datom-count)}]) | ||
(pprint/pprint errors) | ||
(worker-util/post-message :notification | ||
[(str "Validation detected " (count errors) " invalid block(s). These blocks may be buggy when you interact with them. See the javascript console for more.") | ||
:warning false])) | ||
|
||
(worker-util/post-message :notification | ||
[(str "Your graph is valid! " (assoc (counts-from-entities entities) :datoms datom-count)) | ||
:success false])))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters