Skip to content

Commit

Permalink
Remove more unused fns
Browse files Browse the repository at this point in the history
  • Loading branch information
logseq-cldwalker committed Jan 27, 2022
1 parent 4ce3db2 commit b3ee61b
Show file tree
Hide file tree
Showing 18 changed files with 19 additions and 271 deletions.
6 changes: 5 additions & 1 deletion .carve/config.edn
@@ -1,5 +1,9 @@
{:paths ["src/main" "src/electron" "src/test"]
:api-namespaces [
;; Ignore b/c too many false positives
frontend.db]
frontend.db
;; Used for debugging
frontend.db.debug
;; namespace fns are lazily loaded
frontend.extensions.age-encryption]
:report {:format :ignore}}
56 changes: 12 additions & 44 deletions .carve/ignore
Expand Up @@ -5,7 +5,6 @@ electron.core/stop
;; repl fn
electron.search/query
frontend.blob/blob
frontend.components.sidebar/nav-item
frontend.components.svg/arrow-left
frontend.components.svg/arrow-right
frontend.components.svg/big-arrow-right
Expand Down Expand Up @@ -48,62 +47,31 @@ frontend.components.svg/icon-editor
frontend.components.svg/icon-cli
frontend.components.svg/settings
frontend.components.svg/arrow-expand
frontend.config/git-repo-status-secs
frontend.config/get-subscript
frontend.config/get-superscript
frontend.config/properties-wrapper
frontend.config/get-file-format
frontend.config/default-empty-block
frontend.config/with-code-wrapper
frontend.context.i18n/use-tongue
;; Used by shadow-cljs
frontend.core/stop
frontend.date/ISO-string
frontend.date/get-local-date-time-string
frontend.date/get-month-last-day
frontend.date/int->local-time
frontend.db.debug/qb
frontend.db.debug/check-left-id-conflicts
frontend.db.debug/block-uuid-nil?
frontend.db.model/get-file-by-path
frontend.db.model/get-page-ids-by-names
frontend.db.model/remove-children!
frontend.db.model/with-children-refs
frontend.db.model/db-graph?
frontend.db.model/remove-all-aliases!
frontend.db.model/get-latest-changed-pages
frontend.db.model/remove-orphaned-pages!
frontend.db.outliner/save-block
frontend.db.outliner/remove-non-existed-refs!
frontend.db.react/add-rules-to-inputs
;; For repl
frontend.db.utils/q
;; For debugging
frontend.debug/defn
frontend.debug/print
;; Left as an example
frontend.diff/diffs
frontend.diff/get-patches
frontend.diff/apply-patches!
frontend.extensions.age-encryption/keygen
frontend.extensions.age-encryption/encrypt-with-x25519
frontend.extensions.age-encryption/decrypt-with-x25519
frontend.extensions.age-encryption/encrypt-with-user-passphrase
frontend.extensions.age-encryption/decrypt-with-user-passphrase
;; Lazily loaded
frontend.extensions.code/editor
frontend.extensions.excalidraw/*bounding-width
;; Lazily loaded
frontend.extensions.excalidraw/draw
frontend.extensions.graph/reset-graph!
frontend.extensions.graph.pixi/*dark?
frontend.extensions.pdf.assets/*asset-uploading?
;; Referenced in TODO
frontend.extensions.pdf.utils/get-page-bounding
frontend.extensions.pdf.utils/gen-id
;; For repl
frontend.extensions.zotero.api/item
;; For repl
frontend.external.roam/reset-state!
frontend.format.block/extract-title
frontend.format.block/hiccup-block?
frontend.format.block/definition-list-block?
frontend.format.block/src-block?
;; For repl
frontend.format.mldoc/ast-export-markdown
;; Protocol fn wrapper that could be used
frontend.fs/readdir
frontend.git/log
frontend.git/pull
frontend.git/commit-non-empty
frontend.git/add-commit
frontend.git/find-common-base
Expand Down Expand Up @@ -212,5 +180,5 @@ frontend.util.cursor/move-cursor-to-beginning
frontend.util.pool/terminate-parser-pool!
frontend.util.property/goto-properties-beginning
frontend.util.property/add-page-properties
;; Used by shadow
frontend.worker.parser/init
frontend.react/auto-clean-state
14 changes: 0 additions & 14 deletions src/main/frontend/components/sidebar.cljs
Expand Up @@ -34,20 +34,6 @@
[frontend.mobile.util :as mobile-util]
[frontend.handler.mobile.swipe :as swipe]))

(defn nav-item
[title href svg-d _active? close-modal-fn]
[:a.mb-1.group.flex.items-center.pl-4.py-2.text-base.leading-6.font-medium.hover:text-gray-200.transition.ease-in-out.duration-150.nav-item
{:href href
:on-click close-modal-fn}
[:svg.mr-4.h-6.w-6.group-hover:text-gray-200.group-focus:text-gray-200.transition.ease-in-out.duration-150
{:viewBox "0 0 24 24", :fill "none", :stroke "currentColor"}
[:path
{:d svg-d
:stroke-width "2"
:stroke-linejoin "round"
:stroke-linecap "round"}]]
title])

(rum/defc nav-content-item
[name {:keys [class]} child]

Expand Down
47 changes: 0 additions & 47 deletions src/main/frontend/config.cljs
Expand Up @@ -60,10 +60,6 @@
[]
(or 10 (get-in @state/state [:config :git-push-secs])))

(defn git-repo-status-secs
[]
(or 10 (get-in @state/state [:config :git-push-secs])))

(defn text-formats
[]
(let [config-formats (some->> (get-in @state/state [:config :text-formats])
Expand Down Expand Up @@ -185,14 +181,6 @@
"`"
"")))

(defn get-subscript
[_format]
"_")

(defn get-superscript
[_format]
"^")

(defn get-empty-link-and-forward-pos
[format]
(case format
Expand Down Expand Up @@ -235,13 +223,6 @@
(+ 3 (count label))]
["" 0]))

(defn properties-wrapper
[format]
(case format
:markdown
"---\n\n---"
""))

(defn properties-wrapper-pattern
[format]
(case format
Expand All @@ -256,34 +237,6 @@
"md"
(name format)))

(defn get-file-format
[extension]
(case (keyword extension)
:markdown
:markdown
:md
:markdown
(keyword extension)))

(defn default-empty-block
([format]
(default-empty-block format 2))
([format n]
(let [block-pattern (get-block-pattern format)]
(apply str (repeat n block-pattern)))))

(defn with-code-wrapper
[format mode code]
(let [mode (if-not (string/blank? mode)
(str mode " ")
"")]
(case format
:markdown
(util/format "```%s\n%s\n```" mode code)
:org
(util/format "#+BEGIN_SRC%s\n%s\n#+END_SRC" mode code)
code)))

(defonce default-journals-directory "journals")
(defonce default-pages-directory "pages")
(defonce default-draw-directory "draws")
Expand Down
6 changes: 0 additions & 6 deletions src/main/frontend/context/i18n.cljs
Expand Up @@ -38,9 +38,3 @@
:ok)
(rum/bind-context [*tongue-context* [t preferred-language set-preferred-language]]
children)))

(rum/defc use-tongue []
(rum/with-context [value *tongue-context*]
(if (nil? value)
(throw "use-i18n must be used within a i18n-provider")
value)))
18 changes: 0 additions & 18 deletions src/main/frontend/date.cljs
Expand Up @@ -77,14 +77,6 @@
(catch js/Error _e
nil)))

(defn ISO-string
[]
(.toISOString (js/Date.)))

(defn get-local-date-time-string
[]
(get-date-time-string (tl/local-now)))

(def custom-formatter-2 (tf/formatter "yyyy-MM-dd-HH-mm-ss"))
(defn get-date-time-string-2 []
(tf/unparse custom-formatter-2 (tl/local-now)))
Expand Down Expand Up @@ -145,12 +137,6 @@
[]
(journal-name (t/minus (t/today) (t/days 1))))

(defn get-month-last-day
[]
(let [today (js/Date.)
date (js/Date. (.getFullYear today) (inc (.getMonth today)) 0)]
(.getDate date)))

(defn ymd
([]
(ymd (js/Date.)))
Expand Down Expand Up @@ -249,10 +235,6 @@
[journal-title]
(journal-title-> journal-title format))

(defn int->local-time
[n]
(get-date-time-string (t/to-default-time-zone (tc/from-long n))))

(defn int->local-time-2
[n]
(tf/unparse
Expand Down
49 changes: 0 additions & 49 deletions src/main/frontend/db/model.cljs
Expand Up @@ -272,12 +272,6 @@
conn)
(flatten))))

(defn get-file-by-path
[file-path]
(when-let [repo (state/get-current-repo)]
(when-let [conn (conn/get-conn repo)]
(d/pull conn '[*] [:file/path file-path]))))

(defn get-custom-css
[]
(when-let [repo (state/get-current-repo)]
Expand Down Expand Up @@ -351,16 +345,6 @@
(->> (db-utils/pull-many repo '[:block/name] ids)
(map :block/name)))))

(defn get-page-ids-by-names
([names]
(get-page-ids-by-names (state/get-current-repo) names))
([repo names]
(when repo
(let [lookup-refs (map (fn [name]
[:block/name (util/page-name-sanity-lc name)]) names)]
(->> (db-utils/pull-many repo '[:db/id] lookup-refs)
(mapv :db/id))))))

(defn get-page-alias-names
[repo page-name]
(let [alias-ids (page-alias-set repo page-name)]
Expand Down Expand Up @@ -936,15 +920,6 @@
db-utils/seq-flatten)]
(mapv (fn [page] [page (get-page-alias repo page)]) mentioned-pages))))

(defn remove-children!
[blocks]
(let [parents (->> (mapcat :block/parent blocks)
(map :db/id)
(set))]
(if (seq parents)
(filter (fn [block] (contains? parents (:db/id block))) blocks)
blocks)))

(defn has-children?
([block-id]
(has-children? (state/get-current-repo) block-id))
Expand Down Expand Up @@ -1227,11 +1202,6 @@
[repo]
(db-utils/get-key-value repo :db/type))

(defn db-graph?
"Is current graph a database graph instead of a graph on plain-text files?"
[]
(= :database (get-db-type (state/get-current-repo))))

(defn get-public-pages
[db]
(-> (d/q
Expand Down Expand Up @@ -1436,19 +1406,6 @@
(when (seq pages)
(mapv (fn [page] [:db.fn/retractEntity [:block/name page]]) (map util/page-name-sanity-lc pages)))))

(defn remove-all-aliases!
[repo]
(let [page-ids (->>
(d/q '[:find ?e
:where
[?e :block/alias]]
(conn/get-conn repo))
(apply concat)
(distinct))
tx-data (map (fn [page-id] [:db/retract page-id :block/alias]) page-ids)]
(when (seq tx-data)
(db-utils/transact! repo tx-data))))

(defn set-file-content!
[repo path content]
(when (and repo path)
Expand Down Expand Up @@ -1571,12 +1528,6 @@
(remove nil?))]
orphaned-pages))

(defn remove-orphaned-pages!
([repo] (remove-orphaned-pages! repo (get-orphaned-pages {})))
([repo orphaned-pages]
(let [transaction (mapv (fn [page] [:db/retractEntity (:db/id page)]) orphaned-pages)]
(db-utils/transact! repo transaction))))

(defn get-block-last-direct-child
[db-id]
(when-let [block (db-utils/entity db-id)]
Expand Down
17 changes: 1 addition & 16 deletions src/main/frontend/db/outliner.cljs
@@ -1,8 +1,5 @@
(ns frontend.db.outliner
(:require [datascript.core :as d]
[frontend.db :as db]
[frontend.db.utils :as db-utils]
[frontend.util :as util]))
(:require [datascript.core :as d]))

(defn get-by-id
[conn id]
Expand All @@ -28,14 +25,6 @@
:where
[?a :block/parent ?id]])

(defn save-block
[conn block-m]
(let [tx (-> (dissoc block-m :block/children :block/level :block/meta)
(util/remove-nils))
block-id (:block/uuid block-m)]
(d/transact! conn [tx])
(db-utils/pull [:block/uuid block-id])))

(defn del-block
[conn id-or-look-ref]
(d/transact! conn [[:db.fn/retractEntity id-or-look-ref]]))
Expand All @@ -53,7 +42,3 @@
[?a :block/journal? true]]
@conn)]
(flatten r)))

(defn remove-non-existed-refs!
[refs]
(filter db/entity refs))
7 changes: 1 addition & 6 deletions src/main/frontend/db/react.cljs
Expand Up @@ -12,8 +12,7 @@
[frontend.db.utils :as db-utils]
[frontend.state :as state]
[frontend.util :as util :refer [react]]
[frontend.util.marker :as marker]
[frontend.db.rules :as rules]))
[frontend.util.marker :as marker]))

;; Query atom of map of Key ([repo q inputs]) -> atom
;; TODO: replace with LRUCache, only keep the latest 20 or 50 items?
Expand Down Expand Up @@ -136,10 +135,6 @@
(set! (.-state result-atom) result)
(add-q! k nil nil result-atom identity identity identity))))))

(defn add-rules-to-inputs
[inputs]
(conj (vec inputs) rules/rules))

(defn q
[repo k {:keys [use-cache? transform-fn query-fn inputs-fn disable-reactive?]
:or {use-cache? true
Expand Down

0 comments on commit b3ee61b

Please sign in to comment.