ox-publish: Do not store :title, :date, and :index in project cache

* lisp/ox-publish.el (org-publish-transient-cache): New transient
cache, used just during current publish process.
(org-publish-initialize-cache):
(org-publish-reset-cache): Initialize the transient cache.
(org-publish-cache-set-file-property): Add new optional argument to
store property in transient cache rather than persistent cache.
(org-publish-cache-get-file-property): Query transient cache first.
(org-publish-collect-index):
(org-publish-find-title):
(org-publish-find-date): Use transient cache.

This commit fixes situation when :title/:date/:index properties are
not updated even when the corresponding project file does get updated.

Link: https://emacs-china.org/t/org-mode-html/26896/2
This commit is contained in:
Ihor Radchenko 2024-03-29 12:17:09 +03:00
parent 68d592bae4
commit 510e8f9cc8
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
1 changed files with 33 additions and 16 deletions

View File

@ -56,6 +56,9 @@
"This will cache timestamps and titles for files in publishing projects. "This will cache timestamps and titles for files in publishing projects.
Blocks could hash sha1 values here.") Blocks could hash sha1 values here.")
(defvar org-publish-transient-cache nil
"This will cache information during publishing process.")
(defvar org-publish-after-publishing-hook nil (defvar org-publish-after-publishing-hook nil
"Hook run each time a file is published. "Hook run each time a file is published.
Every function in this hook will be called with two arguments: Every function in this hook will be called with two arguments:
@ -867,7 +870,7 @@ PROPERTY, i.e. \"behavior\" parameter from `org-export-options-alist'."
(org-no-properties (org-no-properties
(org-element-interpret-data parsed-title)) (org-element-interpret-data parsed-title))
(file-name-nondirectory (file-name-sans-extension file))))) (file-name-nondirectory (file-name-sans-extension file)))))
(org-publish-cache-set-file-property file :title title))))) (org-publish-cache-set-file-property file :title title nil 'transient)))))
(defun org-publish-find-date (file project) (defun org-publish-find-date (file project)
"Find the date of FILE in PROJECT. "Find the date of FILE in PROJECT.
@ -892,7 +895,8 @@ time in `current-time' format."
(org-time-string-to-time value)))))) (org-time-string-to-time value))))))
((file-exists-p file) ((file-exists-p file)
(file-attribute-modification-time (file-attributes file))) (file-attribute-modification-time (file-attributes file)))
(t (error "No such file: \"%s\"" file))))))))) (t (error "No such file: \"%s\"" file)))))
nil 'transient))))
(defun org-publish-sitemap-default-entry (entry style project) (defun org-publish-sitemap-default-entry (entry style project)
"Default format for site map ENTRY, as a string. "Default format for site map ENTRY, as a string.
@ -1048,7 +1052,8 @@ its CDR is a string."
(replace-regexp-in-string (replace-regexp-in-string
"\\[[0-9]+%\\]\\|\\[[0-9]+/[0-9]+\\]" "" "\\[[0-9]+%\\]\\|\\[[0-9]+/[0-9]+\\]" ""
(org-element-property :raw-value parent))))))))) (org-element-property :raw-value parent)))))))))
info)))) info))
nil 'transient))
;; Return output unchanged. ;; Return output unchanged.
output) output)
@ -1251,6 +1256,9 @@ If FREE-CACHE, empty the cache."
(error "Org publish timestamp: %s is not a directory" (error "Org publish timestamp: %s is not a directory"
org-publish-timestamp-directory)) org-publish-timestamp-directory))
(unless org-publish-transient-cache
(setq org-publish-transient-cache (make-hash-table :test #'equal)))
(unless (and org-publish-cache (unless (and org-publish-cache
(string= (org-publish-cache-get ":project:") project-name)) (string= (org-publish-cache-get ":project:") project-name))
(let* ((cache-file (let* ((cache-file
@ -1274,6 +1282,8 @@ If FREE-CACHE, empty the cache."
(message "%s" "Resetting org-publish-cache") (message "%s" "Resetting org-publish-cache")
(when (hash-table-p org-publish-cache) (when (hash-table-p org-publish-cache)
(clrhash org-publish-cache)) (clrhash org-publish-cache))
(when (hash-table-p org-publish-transient-cache)
(clrhash org-publish-transient-cache))
(setq org-publish-cache nil)) (setq org-publish-cache nil))
(defun org-publish-cache-file-needs-publishing (defun org-publish-cache-file-needs-publishing
@ -1319,16 +1329,22 @@ the file including them will be republished as well."
included-files-mtime)))))) included-files-mtime))))))
(defun org-publish-cache-set-file-property (defun org-publish-cache-set-file-property
(filename property value &optional project-name) (filename property value &optional project-name transient)
"Set the VALUE for a PROPERTY of file FILENAME in publishing cache to VALUE. "Set the VALUE for a PROPERTY of file FILENAME in publishing cache to VALUE.
Use cache file of PROJECT-NAME. If the entry does not exist, it Use cache file of PROJECT-NAME. If the entry does not exist, it
will be created. Return VALUE." will be created. Return VALUE.
When TRANSIENT is non-nil, store value in transient cache that is only
maintained during the current publish process."
;; Evtl. load the requested cache file: ;; Evtl. load the requested cache file:
(when project-name (org-publish-initialize-cache project-name)) (when project-name (org-publish-initialize-cache project-name))
(let ((pl (org-publish-cache-get filename))) (if transient
(if pl (progn (plist-put pl property value) value) (puthash (cons filename property) value
(org-publish-cache-get-file-property org-publish-transient-cache)
filename property value nil project-name)))) (let ((pl (org-publish-cache-get filename)))
(if pl (progn (plist-put pl property value) value)
(org-publish-cache-get-file-property
filename property value nil project-name)))))
(defun org-publish-cache-get-file-property (defun org-publish-cache-get-file-property
(filename property &optional default no-create project-name) (filename property &optional default no-create project-name)
@ -1337,13 +1353,14 @@ Use cache file of PROJECT-NAME. Return the value of that PROPERTY,
or DEFAULT, if the value does not yet exist. Create the entry, or DEFAULT, if the value does not yet exist. Create the entry,
if necessary, unless NO-CREATE is non-nil." if necessary, unless NO-CREATE is non-nil."
(when project-name (org-publish-initialize-cache project-name)) (when project-name (org-publish-initialize-cache project-name))
(let ((properties (org-publish-cache-get filename))) (or (gethash (cons filename property) org-publish-transient-cache)
(cond ((null properties) (let ((properties (org-publish-cache-get filename)))
(unless no-create (cond ((null properties)
(org-publish-cache-set filename (list property default))) (unless no-create
default) (org-publish-cache-set filename (list property default)))
((plist-member properties property) (plist-get properties property)) default)
(t default)))) ((plist-member properties property) (plist-get properties property))
(t default)))))
(defun org-publish-cache-get (key) (defun org-publish-cache-get (key)
"Return the value stored in `org-publish-cache' for key KEY. "Return the value stored in `org-publish-cache' for key KEY.