Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
meedstrom committed Aug 23, 2024
1 parent 61f4569 commit 4580315
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
23 changes: 11 additions & 12 deletions org-node-fakeroam.el
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

(require 'cl-lib)
(require 'ol)
(require 'org-persist)
(require 'org-node)
(require 'org-node-changes)
(if (require 'org-roam nil t)
Expand Down Expand Up @@ -114,6 +113,10 @@ See also `org-node-fakeroam-fast-render-mode'.
(when (boundp 'savehist-additional-variables)
(delete 'org-node--file<>previews savehist-additional-variables)
(delete 'org-node--file<>mtime savehist-additional-variables))
;; Relying only on `kill-emacs-hook' is always a mistake
(run-with-idle-timer 60 t (lambda ()
(persist-save 'org-node--file<>previews)
(persist-save 'org-node--file<>mtime)))
(advice-add #'org-roam-preview-get-contents :around
#'org-node-fakeroam--accelerate-get-contents)
(advice-add #'org-roam-node-insert-section :around
Expand Down Expand Up @@ -270,13 +273,6 @@ Designed to override `org-roam-reflinks-get'."

;;;; Feed method: supply data to Roam's DB

;; (benchmark-call #'org-node-fakeroam-db-rebuild)
;; => (6.598225708 8 1.6199558970000005)
;; (benchmark-run (org-node-fakeroam-db-rebuild))
;; => (13.048531745 8 2.3832248650000025)
;; (benchmark-run (org-roam-db-sync 'force))
;; => (179.921311207 147 37.955398732)

;;;###autoload
(define-minor-mode org-node-fakeroam-db-feed-mode
"Supply data to the org-roam SQLite database on save.
Expand Down Expand Up @@ -325,8 +321,11 @@ Designed to override `org-roam-reflinks-get'."
(org-node-fakeroam--db-add-node node))))))

;; TODO: Was hoping to just run this on every save. Is SQLite really so slow
;; to accept 0-2 MB of data? Must be some way to make it instant, else
;; how do people work with petabytes?
;; to accept 0-2 MB of data? Must be some way to make it instant.
;; (benchmark-run (org-node-fakeroam-db-rebuild))
;; => (13.048531745 8 2.3832248650000025)
;; (benchmark-run (org-roam-db-sync 'force))
;; => (179.921311207 147 37.955398732)
(defun org-node-fakeroam-db-rebuild ()
"Wipe the Roam DB and rebuild."
(when (require 'org-roam nil t)
Expand Down Expand Up @@ -363,9 +362,9 @@ Designed to override `org-roam-reflinks-get'."
(org-roam-db-query [:insert :into files :values $v1]
(vector file
(org-node-get-file-title node)
nil
;; Costs a lot of time
;; HACK: Costs a lot of time, pass a nil hash
;; (ignore-errors (org-roam-db--file-hash file))
nil
(file-attribute-access-time attr)
(file-attribute-modification-time attr))))))

Expand Down
2 changes: 1 addition & 1 deletion org-node.el
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ SYNCHRONOUS t, unless SYNCHRONOUS is the symbol `must-async'."
(when (seq-some #'process-live-p org-node--processes)
(if org-node-cache-mode
(message "org-node first-time caching...")
(message "org-node caching... (Hint: Turn on org-node-cache-mode)")))
(message "org-node caching... (Hint: Avoid this hang by enabling org-node-cache-mode at some point before use)")))
(mapc #'accept-process-output org-node--processes)
;; Just in case... see docstring of `org-node-create'.
;; Not super happy about this edge-case, it's a wart of the current design
Expand Down

0 comments on commit 4580315

Please sign in to comment.