mirror of
https://github.com/org-roam/org-roam
synced 2025-08-01 12:17:21 -05:00
(fix)db: update atime on file access (#2174)
Previously we only updated the database on file save, but we need to update the file's atime on file access, so we hook into `find-file-hook` to do so. We only update the file atime if the file exists in the file table.
This commit is contained in:
@ -695,6 +695,19 @@ If FORCE, force a rebuild of the cache from scratch."
|
|||||||
(lwarn 'org-roam :error "Failed to process %s with error %s, skipping..."
|
(lwarn 'org-roam :error "Failed to process %s with error %s, skipping..."
|
||||||
file (error-message-string err))))))))
|
file (error-message-string err))))))))
|
||||||
|
|
||||||
|
(defun org-roam-db--update-file-atime-h ()
|
||||||
|
"Update atime in the files table on file-access."
|
||||||
|
(let* ((f (buffer-file-name (buffer-base-buffer)))
|
||||||
|
(file-in-db-p (> (caar (org-roam-db-query [:select (funcall count file) :from files
|
||||||
|
:where (= file $s1)] f)) 0))
|
||||||
|
(new-atime (file-attribute-access-time (file-attributes f))))
|
||||||
|
(when file-in-db-p
|
||||||
|
(org-roam-db-query [:update (atime)
|
||||||
|
:in files
|
||||||
|
:values $v1
|
||||||
|
:where (= file $s2)]
|
||||||
|
[new-atime] f))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(define-minor-mode org-roam-db-autosync-mode
|
(define-minor-mode org-roam-db-autosync-mode
|
||||||
"Global minor mode to keep your Org-roam session automatically synchronized.
|
"Global minor mode to keep your Org-roam session automatically synchronized.
|
||||||
@ -712,12 +725,14 @@ database, see `org-roam-db-sync' command."
|
|||||||
(cond
|
(cond
|
||||||
(enabled
|
(enabled
|
||||||
(add-hook 'find-file-hook #'org-roam-db-autosync--setup-file-h)
|
(add-hook 'find-file-hook #'org-roam-db-autosync--setup-file-h)
|
||||||
|
(add-hook 'find-file-hook #'org-roam-db--update-file-atime-h)
|
||||||
(add-hook 'kill-emacs-hook #'org-roam-db--close-all)
|
(add-hook 'kill-emacs-hook #'org-roam-db--close-all)
|
||||||
(advice-add #'rename-file :after #'org-roam-db-autosync--rename-file-a)
|
(advice-add #'rename-file :after #'org-roam-db-autosync--rename-file-a)
|
||||||
(advice-add #'delete-file :before #'org-roam-db-autosync--delete-file-a)
|
(advice-add #'delete-file :before #'org-roam-db-autosync--delete-file-a)
|
||||||
(org-roam-db-sync))
|
(org-roam-db-sync))
|
||||||
(t
|
(t
|
||||||
(remove-hook 'find-file-hook #'org-roam-db-autosync--setup-file-h)
|
(remove-hook 'find-file-hook #'org-roam-db-autosync--setup-file-h)
|
||||||
|
(remove-hook 'find-file-hook #'org-roam-db--update-file-atime-h)
|
||||||
(remove-hook 'kill-emacs-hook #'org-roam-db--close-all)
|
(remove-hook 'kill-emacs-hook #'org-roam-db--close-all)
|
||||||
(advice-remove #'rename-file #'org-roam-db-autosync--rename-file-a)
|
(advice-remove #'rename-file #'org-roam-db-autosync--rename-file-a)
|
||||||
(advice-remove #'delete-file #'org-roam-db-autosync--delete-file-a)
|
(advice-remove #'delete-file #'org-roam-db-autosync--delete-file-a)
|
||||||
|
@ -73,7 +73,7 @@ It takes a single argument NODE, which is an `org-roam-node' construct."
|
|||||||
:group 'org-roam
|
:group 'org-roam
|
||||||
:type 'function)
|
:type 'function)
|
||||||
|
|
||||||
(defcustom org-roam-node-default-sort 'file-mtime
|
(defcustom org-roam-node-default-sort 'file-atime
|
||||||
"Default sort order for Org-roam node completions."
|
"Default sort order for Org-roam node completions."
|
||||||
:type '(choice
|
:type '(choice
|
||||||
(const :tag "none" nil)
|
(const :tag "none" nil)
|
||||||
|
Reference in New Issue
Block a user