Explorar el Código

enhance: also replace distinct-by in deps/graph-parser & electron/search

rcmerci hace 3 años
padre
commit
db7975d09f

+ 8 - 7
deps/graph-parser/deps.edn

@@ -4,20 +4,21 @@
  {com.andrewmcveigh/cljs-time {:git/url "https://github.com/logseq/cljs-time" ;; fork
                                :sha     "5704fbf48d3478eedcf24d458c8964b3c2fd59a9"}
   ;; local dep
-  logseq/db {:local/root "../db"}
+  logseq/db                   {:local/root "../db"}
   ;; stubbed in nbb
-  com.lambdaisland/glogi {:mvn/version "1.1.144"}
+  com.lambdaisland/glogi      {:mvn/version "1.1.144"}
   ;; built in to nbb
-  cljs-bean/cljs-bean {:mvn/version "1.5.0"}}
+  cljs-bean/cljs-bean         {:mvn/version "1.5.0"}
+  medley/medley               {:mvn/version "1.4.0"}}
 
  :aliases
  ;; This runs tests with nodejs. Would be nice to run this with in a browser env
  ;; since this is how its normally run in the app but this requires more setup
  ;; with karma, shadow-cljs.edn and headless mode on CI
  {:test {:extra-paths ["test"]
-         :extra-deps {olical/cljs-test-runner {:mvn/version "3.8.0"}
-                      org.clojure/clojurescript {:mvn/version "1.11.54"}}
-         :main-opts ["-m" "cljs-test-runner.main"]}
+         :extra-deps  {olical/cljs-test-runner   {:mvn/version "3.8.0"}
+                       org.clojure/clojurescript {:mvn/version "1.11.54"}}
+         :main-opts   ["-m" "cljs-test-runner.main"]}
 
   :clj-kondo {:replace-deps {clj-kondo/clj-kondo {:mvn/version "2022.12.08"}}
-              :main-opts  ["-m" "clj-kondo.main"]}}}
+              :main-opts    ["-m" "clj-kondo.main"]}}}

+ 2 - 8
deps/graph-parser/src/logseq/graph_parser/util.cljs

@@ -5,6 +5,7 @@
             [clojure.edn :as edn]
             [clojure.string :as string]
             [clojure.walk :as walk]
+            [medley.core :as medley]
             [logseq.graph-parser.log :as log]))
 
 (defn safe-decode-uri-component
@@ -158,15 +159,8 @@
            (string/join " ")))
 
 (defn distinct-by
-  "Copy of frontend.util/distinct-by. Too basic to couple to main app"
   [f col]
-  (reduce
-   (fn [acc x]
-     (if (some #(= (f x) (f %)) acc)
-       acc
-       (vec (conj acc x))))
-   []
-   col))
+  (medley/distinct-by f (seq col)))
 
 (defn normalize-format
   [format]

+ 3 - 8
src/electron/electron/search.cljs

@@ -5,7 +5,8 @@
             ["better-sqlite3" :as sqlite3]
             [clojure.string :as string]
             ["electron" :refer [app]]
-            [electron.logger :as logger]))
+            [electron.logger :as logger]
+            [medley.core :as medley]))
 
 (defonce databases (atom nil))
 
@@ -240,13 +241,7 @@
 
 (defn distinct-by
   [f col]
-  (reduce
-   (fn [acc x]
-     (if (some #(= (f x) (f %)) acc)
-       acc
-       (vec (conj acc x))))
-   []
-   col))
+  (medley/distinct-by f (seq col)))
 
 (defn search-blocks
   ":page - the page to specificly search on"