Просмотр исходного кода

Merge branch 'feat/db' into perf/app-start

Tienson Qin 8 месяцев назад
Родитель
Сommit
f5342c3192

+ 6 - 5
deps/db/src/logseq/db/frontend/property.cljs

@@ -548,12 +548,13 @@
      :logseq.property.history/scalar-value {:title "History scalar value"
                                             :schema {:type :any
                                                      :hide? true}}
-     :logseq.property/created-by {:title "Node created by"
-                                  :schema {;; user-uuid, why not ref?
-                                           ;; - avoid losing this attr when the user-block is deleted
-                                           ;; - related user-block maybe not exists yet in graph
-                                           :type :string
+     :logseq.property/created-by {:title "Node created by(deprecated)"
+                                  :schema {:type :string
                                            :hide? true}}
+     :logseq.property/created-by-ref {:title "Node created by"
+                                      :schema {:type :entity
+                                               :hide? true}
+                                      :queryable? true}
      :logseq.property/used-template {:title "Used template"
                                      :schema {:type :node
                                               :public? false

+ 1 - 1
deps/db/src/logseq/db/frontend/schema.cljs

@@ -37,7 +37,7 @@
          (map (juxt :major :minor)
               [(parse-schema-version x) (parse-schema-version y)])))
 
-(def version (parse-schema-version "64.4"))
+(def version (parse-schema-version "64.5"))
 
 (defn major-version
   "Return a number.

+ 7 - 1
deps/graph-parser/src/logseq/graph_parser/block.cljs

@@ -374,6 +374,11 @@
    `skip-existing-page-check?`: if true, allows pages to have the same name"
   [original-page-name db with-timestamp? date-formatter
    & {:keys [page-uuid class? created-by] :as options}]
+  (assert (or (nil? created-by)
+              (and (map? created-by)
+                   (:block/uuid created-by)
+                   (:logseq.property.user/name created-by)))
+          created-by)
   (when-not (and db (common-util/uuid-string? original-page-name)
                  (not (ldb/page? (d/entity db [:block/uuid (uuid original-page-name)]))))
     (let [db-based? (ldb/db-based-graph? db)
@@ -400,7 +405,8 @@
                          (or (:block/tags page)
                              [:logseq.class/Page]))]
             (cond-> (assoc page :block/tags tags)
-              created-by (assoc :logseq.property/created-by created-by)))
+              created-by
+              (assoc :logseq.property/created-by-ref created-by)))
           (assoc page :block/type (or (:block/type page) "page")))))))
 
 (defn- db-namespace-page?

+ 10 - 6
deps/outliner/src/logseq/outliner/core.cljs

@@ -54,9 +54,13 @@
 
 (defn- update-property-created-by
   [block created-by]
+  (assert (and (map? created-by)
+               (:block/uuid created-by)
+               (:logseq.property.user/name created-by))
+          created-by)
   (cond-> block
-    (and created-by (nil? (:logseq.property/created-by block)))
-    (assoc :logseq.property/created-by created-by)))
+    (and created-by (nil? (:logseq.property/created-by-ref block)))
+    (assoc :logseq.property/created-by-ref created-by)))
 
 (defn- filter-top-level-blocks
   [db blocks]
@@ -657,7 +661,7 @@
       `replace-empty-target?`: If the `target-block` is an empty block, whether
                                to replace it, it defaults to be `false`.
       `update-timestamps?`: whether to update `blocks` timestamps.
-      `created-by`: user-uuid, update `:logseq.property/created-by` if exists
+      `created-by`: user-block, update `:logseq.property/created-by-ref` if exists
     ``"
   [repo conn blocks target-block {:keys [keep-uuid? keep-block-order?
                                          outliner-op replace-empty-target? update-timestamps?
@@ -701,9 +705,9 @@
                         true
                         (mapv block-with-timestamps)
                         db-based?
-                        (mapv #(-> %
-                                   (dissoc :block/properties)
-                                   (update-property-created-by created-by)))))
+                        (mapv #(cond-> %
+                                 true (dissoc :block/properties)
+                                 created-by (update-property-created-by created-by)))))
             insert-opts {:sibling? sibling?
                          :replace-empty-target? replace-empty-target?
                          :keep-uuid? keep-uuid?

+ 34 - 24
src/main/frontend/components/block.cljs

@@ -2169,30 +2169,40 @@
                                         (assoc :class "selected"))
                          (when
                           order-list?
-                           [:label (str order-list-idx ".")])])]]]
-         (cond
-           (and (or (mobile-util/native-platform?)
-                    (:ui/show-empty-bullets? (state/get-config))
-                    collapsed?
-                    collapsable?
-                    (< (- (util/time-ms) (:block/created-at block)) 500))
-                (not doc-mode?))
-           bullet
-
-           (or
-            (and empty-content?
-                 (not edit?)
-                 (not top?)
-                 (not bottom?)
-                 (not (util/react *control-show?))
-                 (not (:logseq.property/created-from-property  block)))
-            (and doc-mode?
-                 (not collapsed?)
-                 (not (util/react *control-show?))))
-           [:span.bullet-container]
-
-           :else
-           bullet)))]))
+                           [:label (str order-list-idx ".")])])]]
+             bullet' (cond
+                       (and (or (mobile-util/native-platform?)
+                                (:ui/show-empty-bullets? (state/get-config))
+                                collapsed?
+                                collapsable?
+                                (< (- (util/time-ms) (:block/created-at block)) 500))
+                            (not doc-mode?))
+                       bullet
+
+                       (or
+                        (and empty-content?
+                             (not edit?)
+                             (not top?)
+                             (not bottom?)
+                             (not (util/react *control-show?))
+                             (not (:logseq.property/created-from-property  block)))
+                        (and doc-mode?
+                             (not collapsed?)
+                             (not (util/react *control-show?))))
+                       [:span.bullet-container]
+
+                       :else
+                       bullet)]
+         (if (config/db-based-graph?)
+           (ui/tippy
+            {:html (fn []
+                     [:div.flex.flex-col.gap-1.p-2
+                      (when-let [created-by (and (ldb/get-graph-rtc-uuid (db/get-db)) (:logseq.property/created-by-ref block))]
+                        [:div (:block/title created-by)])
+                      [:div "Created: " (date/int->local-time-2 (:block/created-at block))]
+                      [:div "Last edited: " (date/int->local-time-2 (:block/updated-at block))]])}
+            bullet')
+           bullet')))]))
 
 (rum/defc dnd-separator
   [move-to block-content?]

+ 2 - 1
src/main/frontend/extensions/pdf/assets.cljs

@@ -43,11 +43,12 @@
   [original-path & {:keys [href block]}]
   (let [web-link? (string/starts-with? original-path "http")
         blob-res? (some-> href (string/starts-with? "blob"))
+        asset-res? (some-> href (string/starts-with? "assets"))
         filename  (util/node-path.basename original-path)
         ext-name  "pdf"
         url       (if blob-res? href
                       (assets-handler/normalize-asset-resource-url original-path))
-        filename' (if (or web-link? blob-res?) filename
+        filename' (if (or asset-res? web-link? blob-res?) filename
                       (some-> (get-in-repo-assets-full-filename url)
                               (js/decodeURIComponent) (string/replace '"/" "_")))
         filekey   (util/safe-sanitize-file-name

+ 9 - 9
src/main/frontend/extensions/pdf/core.cljs

@@ -688,15 +688,15 @@
        (when-let [grouped-hls (and (sequential? highlights) (group-by :page highlights))]
          (doseq [page loaded-pages]
            (when-let [^js/HTMLDivElement hls-layer (pdf-utils/resolve-hls-layer! viewer page)]
-             (let [page-hls (get grouped-hls page)]
-
-               (rum/mount
-                (pdf-highlights-region-container
-                 viewer page-hls {:show-ctx-menu! show-ctx-menu!
-                                  :upd-hl!        upd-hl!})
-
-                hls-layer)))))
-
+             (let [page-hls (get grouped-hls page)
+                   hls-render (pdf-highlights-region-container
+                               viewer page-hls {:show-ctx-menu! show-ctx-menu!
+                                                :upd-hl! upd-hl!})
+                   ^js mounted-root (.-mountedRoot hls-layer)]
+               (if (nil? mounted-root)
+                 (->> (rum/mount hls-render hls-layer)
+                      (set! (. hls-layer -mountedRoot)))
+                 (.render mounted-root hls-render))))))
        ;; destroy
        #())
      [loaded-pages highlights])

+ 3 - 4
src/main/frontend/handler/common/page.cljs

@@ -60,13 +60,12 @@
        (if (and has-tags? (nil? title'))
          (notification/show! "Page name can't include \"#\"." :warning)
          (when-not (string/blank? title')
-           (p/let [current-user-id (user/user-uuid)
-                   options' (if db-based?
+           (p/let [options' (if db-based?
                               (cond-> (update options :tags concat (:block/tags parsed-result))
                                 (nil? (:split-namespace? options))
                                 (assoc :split-namespace? true)
-                                current-user-id
-                                (assoc :created-by current-user-id))
+                                true
+                                (assoc :created-by (user/user-block)))
                               options)
                    [_page-name page-uuid] (ui-outliner-tx/transact!
                                            {:outliner-op :create-page}

+ 14 - 13
src/main/frontend/handler/editor.cljs

@@ -335,8 +335,7 @@
                    true
 
                    :else
-                   (not has-children?))
-        current-user-id (user/user-uuid)]
+                   (not has-children?))]
     (ui-outliner-tx/transact!
      {:outliner-op :insert-blocks}
      (save-current-block! {:current-block current-block})
@@ -344,7 +343,7 @@
                                                             :keep-uuid? keep-uuid?
                                                             :ordered-list? ordered-list?
                                                             :replace-empty-target? replace-empty-target?
-                                                            :created-by current-user-id}))))
+                                                            :created-by (user/user-block)}))))
 
 (defn- block-self-alone-when-insert?
   [config uuid]
@@ -1433,16 +1432,18 @@
                            (string/replace #"^[.\/\\]*assets[\/\\]+" ""))
               dir (or (:dir matched-alias) repo-dir)]
         (if (util/electron?)
-          (let [from (not-empty (.-path file))]
-            (js/console.debug "Debug: Copy Asset #" dir file-rpath from)
-            (-> (js/window.apis.copyFileToAssets dir file-rpath from)
-                (p/then
-                 (fn [dest]
-                   [file-rpath
-                    (if (string? dest) (js/File. #js[] dest) file)
-                    (path/path-join dir file-rpath)
-                    matched-alias]))
-                (p/catch #(js/console.error "Debug: Copy Asset Error#" %))))
+          (do (js/console.debug "Debug: Copy Asset #" dir file-rpath)
+              (-> (if-let [from (not-empty (.-path file))]
+                    (js/window.apis.copyFileToAssets dir file-rpath from)
+                    (p/let [content (.arrayBuffer file)]
+                      (fs/write-file! repo repo-dir file-rpath content {:skip-compare? true})))
+                  (p/then
+                   (fn [dest]
+                     [file-rpath
+                      (if (string? dest) (js/File. #js[] dest) file)
+                      (path/path-join dir file-rpath)
+                      matched-alias]))
+                  (p/catch #(js/console.error "Debug: Copy Asset Error#" %))))
 
           (->
            (p/do! (js/console.debug "Debug: Writing Asset #" dir file-rpath)

+ 13 - 0
src/main/frontend/handler/user.cljs

@@ -85,6 +85,19 @@
    parse-jwt
    :sub))
 
+(defn user-block
+  "FIXME: move to somewhere else?"
+  []
+  (when-let [user-uuid* (user-uuid)]
+    (let [user-name (username)
+          email* (email)]
+      {:block/uuid (uuid user-uuid*)
+       :block/name user-name
+       :block/title user-name
+       :block/tags :logseq.class/Page
+       :logseq.property.user/name user-name
+       :logseq.property.user/email email*})))
+
 (defn logged-in? []
   (some? (state/get-auth-refresh-token)))
 

+ 2 - 1
src/main/frontend/worker/db/migrate.cljs

@@ -768,7 +768,8 @@
             :fix migrate-views}]
    ["64.3" {:properties [:logseq.property/used-template :logseq.property/template-applied-to]
             :classes [:logseq.class/Template]}]
-   ["64.4" {:fix add-group-by-property-for-list-views}]])
+   ["64.4" {:properties [:logseq.property/created-by-ref]}]
+   ["64.5" {:fix add-group-by-property-for-list-views}]])
 
 (let [[major minor] (last (sort (map (comp (juxt :major :minor) db-schema/parse-schema-version first)
                                      schema-version->updates)))

+ 1 - 1
src/main/frontend/worker/handler/page.cljs

@@ -34,7 +34,7 @@
    * :tags                     - tag uuids that are added to :block/tags
    * :persist-op?              - when true, add an update-page op
    * :properties               - properties to add to the page
-   * :created-by               - when set, set :logseq.property/created-by, only for db-based-graphs
+   * :created-by               - user-block, when set, set :logseq.property/created-by-ref, only for db-based-graphs
   TODO: Add other options"
   [repo conn config title & {:as options}]
   (if (ldb/db-based-graph? @conn)