From e0f519b7abbcf2afe9de3f86251612dfba7c55ac Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Mon, 17 Apr 2023 14:48:44 +0800 Subject: [PATCH 1/4] fix: query searching for two or more properties is extremely slow close #8947 --- deps/db/src/logseq/db/rules.cljc | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/deps/db/src/logseq/db/rules.cljc b/deps/db/src/logseq/db/rules.cljc index df688d072..a6d5391d3 100644 --- a/deps/db/src/logseq/db/rules.cljc +++ b/deps/db/src/logseq/db/rules.cljc @@ -131,13 +131,10 @@ [?b :block/properties ?prop] [(missing? $ ?b :block/name)] [(get ?prop ?key) ?v] - (or-join [?v] - [(= ?v ?val)] - [(contains? ?v ?val)] - ;; For integer pages that aren't strings - (and - [(str ?val) ?str-val] - [(contains? ?v ?str-val)]))] + [(str ?val) ?str-val] + (or [(= ?v ?val)] + [(contains? ?v ?val)] + [(contains? ?v ?str-val)])] :page-ref '[(page-ref ?b ?page-name) From 9adb8646b0655cfcac91b48a6d695fcd263f2bfc Mon Sep 17 00:00:00 2001 From: Zhizhen He Date: Mon, 17 Apr 2023 12:19:48 +0800 Subject: [PATCH 2/4] chore: remove duplicated item --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 09eea9e9b..dd4194aae 100644 --- a/.gitignore +++ b/.gitignore @@ -51,7 +51,6 @@ startup.png /src/test/docs* ~*~ -ios/App/App/capacitor.config.json android/app/src/main/assets/capacitor.config.json *.sublime-* From b359718f4aaf78c97271daecaf11de2181a0ca05 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Tue, 18 Apr 2023 14:01:13 +0800 Subject: [PATCH 3/4] fix: insert properties will truncate other properties if there's any empty property (#9117) fix: insert properties not working when there's any empty property --- .../src/logseq/graph_parser/text.cljs | 3 --- src/main/frontend/util/property.cljs | 4 ++-- .../frontend/handler/repo_conversion_test.cljs | 2 +- src/test/frontend/util/property_test.cljs | 16 ++++++++++++++-- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/deps/graph-parser/src/logseq/graph_parser/text.cljs b/deps/graph-parser/src/logseq/graph_parser/text.cljs index ead6445c5..d24abc873 100644 --- a/deps/graph-parser/src/logseq/graph_parser/text.cljs +++ b/deps/graph-parser/src/logseq/graph_parser/text.cljs @@ -174,9 +174,6 @@ (name k)) v' - (string/blank? v') - nil - (gp-util/wrapped-by-quotes? v') v' diff --git a/src/main/frontend/util/property.cljs b/src/main/frontend/util/property.cljs index 3aa36b293..1aa6081d5 100644 --- a/src/main/frontend/util/property.cljs +++ b/src/main/frontend/util/property.cljs @@ -45,13 +45,13 @@ [line] (boolean (and (string? line) - (re-find (re-pattern (str "^\\s?[^ ]+" gp-property/colons " ")) line)))) + (re-find (re-pattern (str "^\\s?[^ ]+" gp-property/colons)) line)))) (defn front-matter-property? [line] (boolean (and (string? line) - (util/safe-re-find #"^\s*[^ ]+: " line)))) + (util/safe-re-find #"^\s*[^ ]+:" line)))) (defn get-property-key [line format] diff --git a/src/test/frontend/handler/repo_conversion_test.cljs b/src/test/frontend/handler/repo_conversion_test.cljs index 18ddfa083..1ac0db602 100644 --- a/src/test/frontend/handler/repo_conversion_test.cljs +++ b/src/test/frontend/handler/repo_conversion_test.cljs @@ -63,7 +63,7 @@ (is (= {:title 98 :alias 6 - :tags 2 :permalink 2 + :tags 3 :permalink 2 :name 1 :type 1 :related 1 :sample 1 :click 1 :id 1 :example 1} (docs-graph-helper/get-all-page-properties db)) "Counts for all page properties") diff --git a/src/test/frontend/util/property_test.cljs b/src/test/frontend/util/property_test.cljs index 07fea4680..540f093e5 100644 --- a/src/test/frontend/util/property_test.cljs +++ b/src/test/frontend/util/property_test.cljs @@ -49,7 +49,7 @@ "** hello" (property/remove-properties :markdown "** hello\nx:: y\na::b\n") - "** hello\na::b")) + "** hello")) (testing "properties with blank lines" (are [x y] (= x y) @@ -152,7 +152,19 @@ SCHEDULED: <2021-10-25 Mon>\n:PROPERTIES:\n:a: b\n:END:\nworld\n" "c" "d") "a\nfoo:: [[bar]], [[baz]]\nb" (property/insert-properties :markdown "" {:foo "\"bar, baz\""}) - "foo:: \"bar, baz\"")) + "foo:: \"bar, baz\"" + + (property/insert-properties :markdown "abcd\nempty::" {:id "123" :foo "bar"}) + "abcd\nempty::\nid:: 123\nfoo:: bar" + + (property/insert-properties :markdown "abcd\nempty:: " {:id "123" :foo "bar"}) + "abcd\nempty:: \nid:: 123\nfoo:: bar" + + (property/insert-properties :markdown "abcd\nempty::" {:id "123"}) + "abcd\nempty::\nid:: 123" + + (property/insert-properties :markdown "abcd\nempty::\nanother-empty::" {:id "123"}) + "abcd\nempty::\nanother-empty::\nid:: 123")) (deftest test-build-properties-str (are [x y] (= (property/build-properties-str :mardown x) y) From b8b16548d2577789b499bb3362c6fd675114f81a Mon Sep 17 00:00:00 2001 From: rcmerci Date: Tue, 18 Apr 2023 18:00:27 +0800 Subject: [PATCH 4/4] fix(sync): config.edn & custom.css overwrite by remote versions (#9138) fix(sync): config.edn & custom.css overwrite by remote versions --- src/main/frontend/components/whiteboard.cljs | 2 - src/main/frontend/config.cljs | 7 ++- src/main/frontend/fs/sync.cljs | 60 ++++++++++++-------- src/main/frontend/handler/events.cljs | 6 +- 4 files changed, 42 insertions(+), 33 deletions(-) diff --git a/src/main/frontend/components/whiteboard.cljs b/src/main/frontend/components/whiteboard.cljs index 991cb29c7..7579f10ae 100644 --- a/src/main/frontend/components/whiteboard.cljs +++ b/src/main/frontend/components/whiteboard.cljs @@ -10,7 +10,6 @@ [frontend.db.model :as model] [frontend.handler.common :as common-handler] [frontend.handler.route :as route-handler] - [frontend.handler.config :as config-handler] [frontend.handler.whiteboard :as whiteboard-handler] [frontend.rum :refer [use-bounding-client-rect use-breakpoint use-click-outside]] @@ -311,7 +310,6 @@ (ui/button (t :on-boarding/welcome-whiteboard-modal-skip) :on-click close-fn :background "gray" :class "opacity-60") (ui/button (t :on-boarding/welcome-whiteboard-modal-start) :on-click (fn [] - (config-handler/set-config! :feature/enable-whiteboards? true) (quick-tour/ready (fn [] (quick-tour/start-whiteboard) diff --git a/src/main/frontend/config.cljs b/src/main/frontend/config.cljs index 3a7dc232e..8aff2d441 100644 --- a/src/main/frontend/config.cljs +++ b/src/main/frontend/config.cljs @@ -8,7 +8,9 @@ [logseq.common.path :as path] [logseq.graph-parser.config :as gp-config] [logseq.graph-parser.util :as gp-util] - [shadow.resource :as rc])) + [shadow.resource :as rc] + [goog.crypt.Md5] + [goog.crypt :as crypt])) (goog-define DEV-RELEASE false) (defonce dev-release? DEV-RELEASE) @@ -338,6 +340,9 @@ (def export-css-file "export.css") (def custom-js-file "custom.js") (def config-default-content (rc/inline "config.edn")) +(def config-default-content-md5 (let [md5 (new crypt/Md5)] + (.update md5 (crypt/stringToUtf8ByteArray config-default-content)) + (crypt/byteArrayToHex (.digest md5)))) ;; NOTE: repo-url is the unique identifier of a repo. ;; - `local` => in-memory demo graph diff --git a/src/main/frontend/fs/sync.cljs b/src/main/frontend/fs/sync.cljs index caa2aa0ea..df2cd3387 100644 --- a/src/main/frontend/fs/sync.cljs +++ b/src/main/frontend/fs/sync.cljs @@ -592,10 +592,16 @@ "when diff all remote files and local files, following remote files always need to download(when checksum not matched), even local-file's last-modified > remote-file's last-modified. because these files will be auto created when the graph created, we dont want them to re-write related remote files." - #{"logseq/config.edn" "logseq/custom.css" - "pages/contents.md" "pages/contents.org" + #{"pages/contents.md" "pages/contents.org" "logseq/metadata.edn"}) +(def ^:private ignore-default-value-files + "when create a new local graph, some files will be created (config.edn, custom.css). + And related remote files wins if these files have default template value." + #{"logseq/config.edn" "logseq/custom.css"}) + +(def ^:private empty-custom-css-md5 "d41d8cd98f00b204e9800998ecf8427e") + ;; TODO: use fn some to filter FileMetadata here, it cause too much loop (defn diff-file-metadata-sets "Find the `FileMetadata`s that exists in s1 and does not exist in s2, @@ -605,29 +611,33 @@ keep this `FileMetadata` in result" [s1 s2] (reduce - (fn [result item] - (let [path (:path item) - lower-case-path (some-> path string/lower-case) - ;; encrypted-path (:encrypted-path item) - checksum (:etag item) - last-modified (:last-modified item)] - (if (some - #(cond - (not= lower-case-path (some-> (:path %) string/lower-case)) - false - (= checksum (:etag %)) - true - (>= last-modified (:last-modified %)) - false - ;; these special files have higher priority in s1 - (contains? higher-priority-remote-files path) - false - (< last-modified (:last-modified %)) - true) - s2) - result - (conj result item)))) - #{} s1)) + (fn [result item] + (let [path (:path item) + lower-case-path (some-> path string/lower-case) + ;; encrypted-path (:encrypted-path item) + checksum (:etag item) + last-modified (:last-modified item)] + (if (some + #(cond + (not= lower-case-path (some-> (:path %) string/lower-case)) + false + (= checksum (:etag %)) + true + (>= last-modified (:last-modified %)) + false + ;; these special files have higher priority in s1 + (contains? higher-priority-remote-files path) + false + ;; higher priority in s1 when config.edn=default value or empty custom.css + (and (contains? ignore-default-value-files path) + (#{config/config-default-content-md5 empty-custom-css-md5} (:etag %))) + false + (< last-modified (:last-modified %)) + true) + s2) + result + (conj result item)))) + #{} s1)) (comment (defn map->FileMetadata [m] diff --git a/src/main/frontend/handler/events.cljs b/src/main/frontend/handler/events.cljs index 5437b2b8a..98a5700f2 100644 --- a/src/main/frontend/handler/events.cljs +++ b/src/main/frontend/handler/events.cljs @@ -37,7 +37,6 @@ [frontend.fs.watcher-handler :as fs-watcher] [frontend.handler.command-palette :as cp] [frontend.handler.common :as common-handler] - [frontend.handler.config :as config-handler] [frontend.handler.editor :as editor-handler] [frontend.handler.file :as file-handler] [frontend.handler.file-sync :as file-sync-handler] @@ -89,10 +88,7 @@ (defn- enable-beta-features! [] (when-not (false? (state/enable-sync?)) ; user turns it off - (file-sync-handler/set-sync-enabled! true)) - - (when-not (false? (state/enable-whiteboards?)) - (config-handler/set-config! :feature/enable-whiteboards? true))) + (file-sync-handler/set-sync-enabled! true))) (defmethod handle :user/fetch-info-and-graphs [[_]] (state/set-state! [:ui/loading? :login] false)