|  | @@ -1,7 +1,5 @@
 | 
											
												
													
														|  |  (ns frontend.db.model
 |  |  (ns frontend.db.model
 | 
											
												
													
														|  |    "Core db functions."
 |  |    "Core db functions."
 | 
											
												
													
														|  | -  ;; TODO: Remove this config once how repos are passed to this ns are standardized
 |  | 
 | 
											
												
													
														|  | -  {:clj-kondo/config {:linters {:unused-binding {:level :off}}}}
 |  | 
 | 
											
												
													
														|  |    (:require [clojure.set :as set]
 |  |    (:require [clojure.set :as set]
 | 
											
												
													
														|  |              [clojure.string :as string]
 |  |              [clojure.string :as string]
 | 
											
												
													
														|  |              [clojure.walk :as walk]
 |  |              [clojure.walk :as walk]
 | 
											
										
											
												
													
														|  | @@ -16,12 +14,10 @@
 | 
											
												
													
														|  |              [frontend.state :as state]
 |  |              [frontend.state :as state]
 | 
											
												
													
														|  |              [frontend.util :as util :refer [react]]
 |  |              [frontend.util :as util :refer [react]]
 | 
											
												
													
														|  |              [logseq.common.util :as common-util]
 |  |              [logseq.common.util :as common-util]
 | 
											
												
													
														|  | -            [logseq.common.util.date-time :as date-time-util]
 |  | 
 | 
											
												
													
														|  |              [logseq.db :as ldb]
 |  |              [logseq.db :as ldb]
 | 
											
												
													
														|  |              [logseq.db.frontend.class :as db-class]
 |  |              [logseq.db.frontend.class :as db-class]
 | 
											
												
													
														|  |              [logseq.db.frontend.content :as db-content]
 |  |              [logseq.db.frontend.content :as db-content]
 | 
											
												
													
														|  | -            [logseq.db.frontend.rules :as rules]
 |  | 
 | 
											
												
													
														|  | -            [logseq.shui.hooks :as hooks]))
 |  | 
 | 
											
												
													
														|  | 
 |  | +            [logseq.db.frontend.rules :as rules]))
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  ;; TODO: extract to specific models and move data transform logic to the
 |  |  ;; TODO: extract to specific models and move data transform logic to the
 | 
											
												
													
														|  |  ;; corresponding handlers.
 |  |  ;; corresponding handlers.
 | 
											
										
											
												
													
														|  | @@ -149,8 +145,7 @@ independent of format as format specific heading characters are stripped"
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  (defn get-page-alias-names
 |  |  (defn get-page-alias-names
 | 
											
												
													
														|  |    [repo page-id]
 |  |    [repo page-id]
 | 
											
												
													
														|  | -  (let [page (db-utils/entity page-id)
 |  | 
 | 
											
												
													
														|  | -        alias-ids (->> (page-alias-set repo page-id)
 |  | 
 | 
											
												
													
														|  | 
 |  | +  (let [alias-ids (->> (page-alias-set repo page-id)
 | 
											
												
													
														|  |                         (remove #{page-id}))]
 |  |                         (remove #{page-id}))]
 | 
											
												
													
														|  |      (when (seq alias-ids)
 |  |      (when (seq alias-ids)
 | 
											
												
													
														|  |        (map (fn [id] (:block/title (db-utils/entity id))) alias-ids))))
 |  |        (map (fn [id] (:block/title (db-utils/entity id))) alias-ids))))
 | 
											
										
											
												
													
														|  | @@ -186,21 +181,6 @@ independent of format as format specific heading characters are stripped"
 | 
											
												
													
														|  |                (when-let [id (:db/id e)]
 |  |                (when-let [id (:db/id e)]
 | 
											
												
													
														|  |                  (db-utils/entity id))))))))
 |  |                  (db-utils/entity id))))))))
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -(defn sub-entity
 |  | 
 | 
											
												
													
														|  | -  "Used for react function components"
 |  | 
 | 
											
												
													
														|  | -  [entity* watch-id]
 |  | 
 | 
											
												
													
														|  | -  (let [id (:db/id entity*)
 |  | 
 | 
											
												
													
														|  | -        *ref (sub-block id {:ref? true})
 |  | 
 | 
											
												
													
														|  | -        [entity set-entity!] (hooks/use-state @*ref)]
 |  | 
 | 
											
												
													
														|  | -    (add-watch *ref watch-id (fn [_ _ _ new-value]
 |  | 
 | 
											
												
													
														|  | -                               (set-entity! new-value)))
 |  | 
 | 
											
												
													
														|  | -    (hooks/use-effect!
 |  | 
 | 
											
												
													
														|  | -     (fn []
 |  | 
 | 
											
												
													
														|  | -       #(remove-watch *ref watch-id))
 |  | 
 | 
											
												
													
														|  | -     [])
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -    [entity set-entity!]))
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  |  (defn sort-by-order-recursive
 |  |  (defn sort-by-order-recursive
 | 
											
												
													
														|  |    [form]
 |  |    [form]
 | 
											
												
													
														|  |    (walk/postwalk (fn [f]
 |  |    (walk/postwalk (fn [f]
 | 
											
										
											
												
													
														|  | @@ -394,27 +374,6 @@ independent of format as format specific heading characters are stripped"
 | 
											
												
													
														|  |                 (:block/name page-entity)
 |  |                 (:block/name page-entity)
 | 
											
												
													
														|  |                 page-name)))))))
 |  |                 page-name)))))))
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -(defn get-journals-length
 |  | 
 | 
											
												
													
														|  | -  []
 |  | 
 | 
											
												
													
														|  | -  (let [today (date-time-util/date->int (js/Date.))]
 |  | 
 | 
											
												
													
														|  | -    (if (config/db-based-graph?)
 |  | 
 | 
											
												
													
														|  | -      (d/q '[:find (count ?page) .
 |  | 
 | 
											
												
													
														|  | -             :in $ ?today
 |  | 
 | 
											
												
													
														|  | -             :where
 |  | 
 | 
											
												
													
														|  | -             [?page :block/tags :logseq.class/Journal]
 |  | 
 | 
											
												
													
														|  | -             [?page :block/journal-day ?journal-day]
 |  | 
 | 
											
												
													
														|  | -             [(<= ?journal-day ?today)]]
 |  | 
 | 
											
												
													
														|  | -           (conn/get-db (state/get-current-repo))
 |  | 
 | 
											
												
													
														|  | -           today)
 |  | 
 | 
											
												
													
														|  | -      (d/q '[:find (count ?page) .
 |  | 
 | 
											
												
													
														|  | -             :in $ ?today
 |  | 
 | 
											
												
													
														|  | -             :where
 |  | 
 | 
											
												
													
														|  | -             [?page :block/type "journal"]
 |  | 
 | 
											
												
													
														|  | -             [?page :block/journal-day ?journal-day]
 |  | 
 | 
											
												
													
														|  | -             [(<= ?journal-day ?today)]]
 |  | 
 | 
											
												
													
														|  | -           (conn/get-db (state/get-current-repo))
 |  | 
 | 
											
												
													
														|  | -           today))))
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  |  (defn get-latest-journals
 |  |  (defn get-latest-journals
 | 
											
												
													
														|  |    ([n]
 |  |    ([n]
 | 
											
												
													
														|  |     (get-latest-journals (state/get-current-repo) n))
 |  |     (get-latest-journals (state/get-current-repo) n))
 | 
											
										
											
												
													
														|  | @@ -430,10 +389,8 @@ independent of format as format specific heading characters are stripped"
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  (defn get-page-referenced-blocks-full
 |  |  (defn get-page-referenced-blocks-full
 | 
											
												
													
														|  |    ([page-id]
 |  |    ([page-id]
 | 
											
												
													
														|  | -   (get-page-referenced-blocks-full (state/get-current-repo) page-id nil))
 |  | 
 | 
											
												
													
														|  | -  ([page-id options]
 |  | 
 | 
											
												
													
														|  | -   (get-page-referenced-blocks-full (state/get-current-repo) page-id options))
 |  | 
 | 
											
												
													
														|  | -  ([repo page-id options]
 |  | 
 | 
											
												
													
														|  | 
 |  | +   (get-page-referenced-blocks-full (state/get-current-repo) page-id))
 | 
											
												
													
														|  | 
 |  | +  ([repo page-id]
 | 
											
												
													
														|  |     (when (and repo page-id)
 |  |     (when (and repo page-id)
 | 
											
												
													
														|  |       (when-let [db (conn/get-db repo)]
 |  |       (when-let [db (conn/get-db repo)]
 | 
											
												
													
														|  |         (let [pages (page-alias-set repo page-id)
 |  |         (let [pages (page-alias-set repo page-id)
 | 
											
										
											
												
													
														|  | @@ -457,10 +414,8 @@ independent of format as format specific heading characters are stripped"
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  (defn get-referenced-blocks
 |  |  (defn get-referenced-blocks
 | 
											
												
													
														|  |    ([eid]
 |  |    ([eid]
 | 
											
												
													
														|  | -   (get-referenced-blocks (state/get-current-repo) eid nil))
 |  | 
 | 
											
												
													
														|  | -  ([eid options]
 |  | 
 | 
											
												
													
														|  | -   (get-referenced-blocks (state/get-current-repo) eid options))
 |  | 
 | 
											
												
													
														|  | -  ([repo eid options]
 |  | 
 | 
											
												
													
														|  | 
 |  | +   (get-referenced-blocks (state/get-current-repo) eid))
 | 
											
												
													
														|  | 
 |  | +  ([repo eid]
 | 
											
												
													
														|  |     (when repo
 |  |     (when repo
 | 
											
												
													
														|  |       (when (conn/get-db repo)
 |  |       (when (conn/get-db repo)
 | 
											
												
													
														|  |         (let [entity (db-utils/entity eid)
 |  |         (let [entity (db-utils/entity eid)
 | 
											
										
											
												
													
														|  | @@ -478,14 +433,12 @@ independent of format as format specific heading characters are stripped"
 | 
											
												
													
														|  |                (util/distinct-by :db/id)))))))
 |  |                (util/distinct-by :db/id)))))))
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  (defn get-block-referenced-blocks
 |  |  (defn get-block-referenced-blocks
 | 
											
												
													
														|  | -  ([block-id]
 |  | 
 | 
											
												
													
														|  | -   (get-block-referenced-blocks block-id {}))
 |  | 
 | 
											
												
													
														|  | -  ([block-id options]
 |  | 
 | 
											
												
													
														|  | -   (when-let [repo (state/get-current-repo)]
 |  | 
 | 
											
												
													
														|  | -     (when (conn/get-db repo)
 |  | 
 | 
											
												
													
														|  | -       (->> (get-referenced-blocks repo block-id options)
 |  | 
 | 
											
												
													
														|  | -            (sort-by-order-recursive)
 |  | 
 | 
											
												
													
														|  | -            db-utils/group-by-page)))))
 |  | 
 | 
											
												
													
														|  | 
 |  | +  [block-id]
 | 
											
												
													
														|  | 
 |  | +  (when-let [repo (state/get-current-repo)]
 | 
											
												
													
														|  | 
 |  | +    (when (conn/get-db repo)
 | 
											
												
													
														|  | 
 |  | +      (->> (get-referenced-blocks repo block-id)
 | 
											
												
													
														|  | 
 |  | +           (sort-by-order-recursive)
 | 
											
												
													
														|  | 
 |  | +           db-utils/group-by-page))))
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  (defn journal-page?
 |  |  (defn journal-page?
 | 
											
												
													
														|  |    "sanitized page-name only"
 |  |    "sanitized page-name only"
 |