mirror of
https://github.com/logseq/logseq.git
synced 2026-05-05 19:36:35 +00:00
enhance: cut memory usage
This commit is contained in:
@@ -471,11 +471,11 @@
|
||||
(update :refs (fn [col] (remove nil? col)))))
|
||||
|
||||
(defn extract-blocks*
|
||||
[blocks pre-block-body pre-block-properties encoded-content]
|
||||
[blocks pre-block-properties encoded-content]
|
||||
(let [first-block (first blocks)
|
||||
first-block-start-pos (get-in first-block [:block/meta :start-pos])
|
||||
blocks (if (or (seq @pre-block-body)
|
||||
(seq @pre-block-properties))
|
||||
blocks (if (or (> first-block-start-pos 0)
|
||||
(empty? blocks))
|
||||
(cons
|
||||
(merge
|
||||
(let [content (utf8/substring encoded-content 0 first-block-start-pos)
|
||||
@@ -486,7 +486,6 @@
|
||||
:meta {:start-pos 0
|
||||
:end-pos (or first-block-start-pos
|
||||
(utf8/length encoded-content))}
|
||||
:body @pre-block-body
|
||||
:properties @pre-block-properties
|
||||
:properties-order (keys @pre-block-properties)
|
||||
:refs (->> (get-page-refs-from-properties @pre-block-properties)
|
||||
@@ -506,11 +505,9 @@
|
||||
(try
|
||||
(let [encoded-content (utf8/encode content)
|
||||
last-pos (utf8/length encoded-content)
|
||||
pre-block-body (atom nil)
|
||||
pre-block-properties (atom nil)
|
||||
blocks
|
||||
(loop [headings []
|
||||
block-body []
|
||||
blocks (reverse blocks)
|
||||
timestamps {}
|
||||
properties {}
|
||||
@@ -527,17 +524,12 @@
|
||||
(paragraph-timestamp-block? block)
|
||||
(let [timestamps (extract-timestamps block)
|
||||
timestamps' (merge timestamps timestamps)
|
||||
[timestamps others] (split-with #(= "Timestamp" (first %)) (second block))
|
||||
other-body (->>
|
||||
(concat
|
||||
timestamps
|
||||
(drop-while #(contains? #{"Hard_Break_Line" "Break_Line"} (first %)) others))
|
||||
(remove nil?))]
|
||||
(recur headings (conj block-body ["Paragraph" other-body]) (rest blocks) timestamps' properties last-pos last-level children (conj block-all-content block-content)))
|
||||
[timestamps others] (split-with #(= "Timestamp" (first %)) (second block))]
|
||||
(recur headings (rest blocks) timestamps' properties last-pos last-level children (conj block-all-content block-content)))
|
||||
|
||||
(property/properties-ast? block)
|
||||
(let [properties (extract-properties (second block))]
|
||||
(recur headings block-body (rest blocks) timestamps properties last-pos last-level children (conj block-all-content block-content)))
|
||||
(recur headings (rest blocks) timestamps properties last-pos last-level children (conj block-all-content block-content)))
|
||||
|
||||
(heading-block? block)
|
||||
(let [id (get-custom-id-or-new-id properties)
|
||||
@@ -568,9 +560,6 @@
|
||||
block (cond->
|
||||
(assoc block
|
||||
:uuid id
|
||||
:body (vec
|
||||
(->> (reverse block-body)
|
||||
(map #(remove-indentations format (:level block) %))))
|
||||
:refs ref-pages-in-properties
|
||||
:children (or current-block-children [])
|
||||
:format format)
|
||||
@@ -600,20 +589,17 @@
|
||||
|
||||
(and updated-at (integer? updated-at))
|
||||
(assoc :block/updated-at updated-at))]
|
||||
(recur (conj headings block) [] (rest blocks) {} {} last-pos' (:level block) children []))
|
||||
(recur (conj headings block) (rest blocks) {} {} last-pos' (:level block) children []))
|
||||
|
||||
:else
|
||||
(let [block-body' (conj block-body block)]
|
||||
(recur headings block-body' (rest blocks) timestamps properties last-pos last-level children (conj block-all-content block-content)))))
|
||||
(recur headings (rest blocks) timestamps properties last-pos last-level children (conj block-all-content block-content))))
|
||||
(do
|
||||
(when (seq block-body)
|
||||
(reset! pre-block-body (reverse block-body)))
|
||||
(when (seq properties)
|
||||
(let [properties (:properties properties)]
|
||||
(reset! pre-block-properties properties)))
|
||||
(-> (reverse headings)
|
||||
safe-blocks))))]
|
||||
(extract-blocks* blocks pre-block-body pre-block-properties encoded-content))
|
||||
(extract-blocks* blocks pre-block-properties encoded-content))
|
||||
(catch js/Error e
|
||||
(js/console.error "extract-blocks-failed")
|
||||
(log/error :exception e))))
|
||||
|
||||
@@ -36,9 +36,10 @@
|
||||
(defn default-config
|
||||
([format]
|
||||
(default-config format {:export-heading-to-list? false}))
|
||||
([format {:keys [export-heading-to-list? export-keep-properties? export-md-indent-style export-md-remove-options]}]
|
||||
([format {:keys [export-heading-to-list? export-keep-properties? export-md-indent-style export-md-remove-options parse_outline_only?]}]
|
||||
(let [format (string/capitalize (name (or format :markdown)))]
|
||||
(->> {:toc false
|
||||
:parse_outline_only (or parse_outline_only? false)
|
||||
:heading_number false
|
||||
:keep_line_break true
|
||||
:format format
|
||||
@@ -198,28 +199,28 @@
|
||||
[]))
|
||||
(log/error :edn/wrong-content-type content)))
|
||||
|
||||
(defn ->edn-async
|
||||
([content config]
|
||||
(->edn-async nil content config))
|
||||
([file content config]
|
||||
(if util/node-test?
|
||||
(p/resolved (->edn content config))
|
||||
(try
|
||||
(if (string/blank? content)
|
||||
(p/resolved [])
|
||||
(p/let [v (pool/add-parse-job! content config)]
|
||||
(try
|
||||
(-> v
|
||||
(util/json->clj)
|
||||
(update-src-full-content content)
|
||||
(collect-page-properties))
|
||||
(catch js/Error e
|
||||
(println :parser/failed file)
|
||||
(js/console.error e)
|
||||
(p/resolved [])))))
|
||||
(catch js/Error e
|
||||
(log/error :parser/failed e)
|
||||
(p/resolved []))))))
|
||||
;; (defn ->edn-async
|
||||
;; ([content config]
|
||||
;; (->edn-async nil content config))
|
||||
;; ([file content config]
|
||||
;; (if util/node-test?
|
||||
;; (p/resolved (->edn content config))
|
||||
;; (try
|
||||
;; (if (string/blank? content)
|
||||
;; (p/resolved [])
|
||||
;; (p/let [v (pool/add-parse-job! content config)]
|
||||
;; (try
|
||||
;; (-> v
|
||||
;; (util/json->clj)
|
||||
;; (update-src-full-content content)
|
||||
;; (collect-page-properties))
|
||||
;; (catch js/Error e
|
||||
;; (println :parser/failed file)
|
||||
;; (js/console.error e)
|
||||
;; (p/resolved [])))))
|
||||
;; (catch js/Error e
|
||||
;; (log/error :parser/failed e)
|
||||
;; (p/resolved []))))))
|
||||
|
||||
(defn opml->edn
|
||||
[content]
|
||||
|
||||
Reference in New Issue
Block a user