Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hook to customize how elfeed-db-gc finds elfeed-refs #457

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion elfeed-db.el
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ the :last-update time is updated.")
(defvar elfeed-db-unload-hook ()
"Hook to run immediately after `elfeed-db-unload'.")

(defvar elfeed-db-gc-trace-functions ()
"A list of functions called to determine which elfeed-ref's are reachable.
Each function is called with an elfeed-entry and should return a
single elfeed-ref or a list of them, which will be considered in
use by `elfeed-db-gc'.")

;; Data model:

(cl-defstruct (elfeed-feed (:constructor elfeed-feed--create))
Expand Down Expand Up @@ -582,7 +588,14 @@ If STATS is true, return the space cleared in bytes."
(with-elfeed-db-visit (entry _)
(let ((content (elfeed-entry-content entry)))
(when (elfeed-ref-p content)
(setf (gethash (elfeed-ref-id content) table) t))))
(setf (gethash (elfeed-ref-id content) table) t)))
(dolist (trace-function elfeed-db-gc-trace-functions)
(let ((refs (funcall trace-function entry)))
(unless (listp refs)
(setf refs (list refs)))
(dolist (ref refs)
(when (elfeed-ref-p ref)
(setf (gethash (elfeed-ref-id ref) table) t))))))
(cl-loop for id hash-keys of table using (hash-value used)
for used-p = (or used (member id '("." "..")))
when (and (not used-p) stats-p)
Expand Down