[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] ox-publish: Do not store :title, :date, and :index in project ca
From: |
Ihor Radchenko |
Subject: |
[PATCH] ox-publish: Do not store :title, :date, and :index in project cache |
Date: |
Fri, 29 Mar 2024 09:21:23 +0000 |
This patch fixes situation when :title/:date/:index properties are
stored in the project cache and then not updated even when the
corresponding project file does get updated.
>From 06bd6a52686ec868a336d89a0ceef4359a71fb14 Mon Sep 17 00:00:00 2001
Message-ID:
<06bd6a52686ec868a336d89a0ceef4359a71fb14.1711703988.git.yantar92@posteo.net>
From: Ihor Radchenko <yantar92@posteo.net>
Date: Fri, 29 Mar 2024 12:17:09 +0300
Subject: [PATCH] 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.
---
lisp/ox-publish.el | 49 +++++++++++++++++++++++++++++++---------------
1 file changed, 33 insertions(+), 16 deletions(-)
diff --git a/lisp/ox-publish.el b/lisp/ox-publish.el
index 9bfd333a4..3e526b813 100644
--- a/lisp/ox-publish.el
+++ b/lisp/ox-publish.el
@@ -56,6 +56,9 @@ (defvar org-publish-cache nil
"This will cache timestamps and titles for files in publishing projects.
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
"Hook run each time a file is published.
Every function in this hook will be called with two arguments:
@@ -867,7 +870,7 @@ (defun org-publish-find-title (file project)
(org-no-properties
(org-element-interpret-data parsed-title))
(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)
"Find the date of FILE in PROJECT.
@@ -892,7 +895,8 @@ (defun org-publish-find-date (file project)
(org-time-string-to-time value))))))
((file-exists-p 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)
"Default format for site map ENTRY, as a string.
@@ -1048,7 +1052,8 @@ (defun org-publish-collect-index (output _backend info)
(replace-regexp-in-string
"\\[[0-9]+%\\]\\|\\[[0-9]+/[0-9]+\\]" ""
(org-element-property :raw-value parent)))))))))
- info))))
+ info))
+ nil 'transient))
;; Return output unchanged.
output)
@@ -1251,6 +1256,9 @@ (defun org-publish-initialize-cache (project-name)
(error "Org publish timestamp: %s is not a 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
(string= (org-publish-cache-get ":project:") project-name))
(let* ((cache-file
@@ -1274,6 +1282,8 @@ (defun org-publish-reset-cache ()
(message "%s" "Resetting org-publish-cache")
(when (hash-table-p 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))
(defun org-publish-cache-file-needs-publishing
@@ -1319,16 +1329,22 @@ (defun org-publish-cache-file-needs-publishing
included-files-mtime))))))
(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.
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:
(when project-name (org-publish-initialize-cache 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))))
+ (if transient
+ (puthash (cons filename property) value
+ org-publish-transient-cache)
+ (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
(filename property &optional default no-create project-name)
@@ -1337,13 +1353,14 @@ (defun org-publish-cache-get-file-property
or DEFAULT, if the value does not yet exist. Create the entry,
if necessary, unless NO-CREATE is non-nil."
(when project-name (org-publish-initialize-cache project-name))
- (let ((properties (org-publish-cache-get filename)))
- (cond ((null properties)
- (unless no-create
- (org-publish-cache-set filename (list property default)))
- default)
- ((plist-member properties property) (plist-get properties property))
- (t default))))
+ (or (gethash (cons filename property) org-publish-transient-cache)
+ (let ((properties (org-publish-cache-get filename)))
+ (cond ((null properties)
+ (unless no-create
+ (org-publish-cache-set filename (list property default)))
+ default)
+ ((plist-member properties property) (plist-get properties
property))
+ (t default)))))
(defun org-publish-cache-get (key)
"Return the value stored in `org-publish-cache' for key KEY.
--
2.44.0
--
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [PATCH] ox-publish: Do not store :title, :date, and :index in project cache,
Ihor Radchenko <=