* [PATCH] ox-publish: Do not store :title, :date, and :index in project cache
@ 2024-03-29 9:21 Ihor Radchenko
2024-04-26 10:45 ` Ihor Radchenko
0 siblings, 1 reply; 2+ messages in thread
From: Ihor Radchenko @ 2024-03-29 9:21 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 177 bytes --]
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.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ox-publish-Do-not-store-title-date-and-index-in-proj.patch --]
[-- Type: text/x-patch, Size: 6004 bytes --]
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
[-- Attachment #3: Type: text/plain, Size: 224 bytes --]
--
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>
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] ox-publish: Do not store :title, :date, and :index in project cache
2024-03-29 9:21 [PATCH] ox-publish: Do not store :title, :date, and :index in project cache Ihor Radchenko
@ 2024-04-26 10:45 ` Ihor Radchenko
0 siblings, 0 replies; 2+ messages in thread
From: Ihor Radchenko @ 2024-04-26 10:45 UTC (permalink / raw)
To: emacs-orgmode
Ihor Radchenko <yantar92@posteo.net> writes:
> 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.
Applied, onto main.
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=510e8f9cc
--
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>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-04-26 10:45 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-29 9:21 [PATCH] ox-publish: Do not store :title, :date, and :index in project cache Ihor Radchenko
2024-04-26 10:45 ` Ihor Radchenko
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).