[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] scratch/org-contacts-rebased c08b676 032/118: Add caching mecanis
From: |
Stefan Monnier |
Subject: |
[elpa] scratch/org-contacts-rebased c08b676 032/118: Add caching mecanism |
Date: |
Fri, 12 Nov 2021 15:36:58 -0500 (EST) |
branch: scratch/org-contacts-rebased
commit c08b6769ae352692342237c3338459ddd74cf2cb
Author: Grégoire Jadi <gregoire.jadi@gmail.com>
Commit: Grégoire Jadi <gregoire.jadi@gmail.com>
Add caching mecanism
* contrib/lisp/org-contacts.el: Add a caching mecanism around
`org-contacts-filter'.
---
org-contacts.el | 74 ++++++++++++++++++++++++++++++++++++++-------------------
1 file changed, 50 insertions(+), 24 deletions(-)
diff --git a/org-contacts.el b/org-contacts.el
index 49bf489..7af8c35 100644
--- a/org-contacts.el
+++ b/org-contacts.el
@@ -139,38 +139,64 @@ This overrides `org-email-link-description-format' if
set."
map)
"The keymap used in `org-contacts' result list.")
+(defvar org-contacts-db nil
+ "Org Contacts database.")
+
+(defvar org-contacts-last-update nil
+ "Last time the Org Contacts database has been updated.")
+
(defun org-contacts-files ()
"Return list of Org files to use for contact management."
(or org-contacts-files (org-agenda-files t 'ifmode)))
-(defun org-contacts-filter (&optional name-match tags-match)
- "Search for a contact maching NAME-MATCH and TAGS-MATCH.
-If both match values are nil, return all contacts."
+(defun org-contacts-db ()
+ "Return the latest Org Contacts Database"
(let* (todo-only
- (tags-matcher
- (if tags-match
- (cdr (org-make-tags-matcher tags-match))
- t))
- (name-matcher
- (if name-match
- '(org-string-match-p name-match (org-get-heading t))
- t))
(contacts-matcher
(cdr (org-make-tags-matcher org-contacts-matcher)))
+ (need-update?
+ (or (null org-contacts-last-update)
+ (some (lambda (file)
+ (time-less-p org-contacts-last-update
+ (elt (file-attributes file) 5)))
+ (org-contacts-files))))
markers result)
- (dolist (file (org-contacts-files))
- (org-check-agenda-file file)
- (with-current-buffer (org-get-agenda-file-buffer file)
- (unless (eq major-mode 'org-mode)
- (error "File %s is no in `org-mode'" file))
- (org-scan-tags
- '(add-to-list 'markers (set-marker (make-marker) (point)))
- `(and ,contacts-matcher ,tags-matcher ,name-matcher)
- todo-only)))
- (dolist (marker markers result)
- (org-with-point-at marker
- (add-to-list 'result
- (list (org-get-heading t) marker (org-entry-properties
marker 'all)))))))
+ (when need-update?
+ (message "Update Org Contacts Database")
+ (dolist (file (org-contacts-files))
+ (org-check-agenda-file file)
+ (with-current-buffer (org-get-agenda-file-buffer file)
+ (unless (eq major-mode 'org-mode)
+ (error "File %s is no in `org-mode'" file))
+ (org-scan-tags
+ '(add-to-list 'markers (set-marker (make-marker) (point)))
+ contacts-matcher
+ todo-only)))
+ (dolist (marker markers result)
+ (org-with-point-at marker
+ (add-to-list 'result
+ (list (org-get-heading t) marker (org-entry-properties
marker 'all)))))
+ (setf org-contacts-db result
+ org-contacts-last-update (current-time)))
+ org-contacts-db))
+
+(defun org-contacts-filter (&optional name-match tags-match)
+ "Search for a contact maching NAME-MATCH and TAGS-MATCH.
+If both match values are nil, return all contacts."
+ (if (and (null name-match)
+ (null tags-match))
+ (org-contacts-db)
+ (loop for contact in (org-contacts-db)
+ if (or
+ (and name-match
+ (org-string-match-p name-match
+ (first contact)))
+ (and tags-match
+ (some (lambda (tag)
+ (org-string-match-p tags-match tag))
+ (org-split-string
+ (or (cdr (assoc-string "ALLTAGS" (caddr contact)))
"") ":"))))
+ collect contact)))
(when (not (fboundp 'completion-table-case-fold))
;; That function is new in Emacs 24...
- [elpa] scratch/org-contacts-rebased 8ccb82f 052/118: org-contacts.el , fix bugs about 'tel and 'note properties, (continued)
- [elpa] scratch/org-contacts-rebased 8ccb82f 052/118: org-contacts.el , fix bugs about 'tel and 'note properties, Stefan Monnier, 2021/11/12
- [elpa] scratch/org-contacts-rebased 5ee8caa 053/118: org-contacts.el, add name alias property., Stefan Monnier, 2021/11/12
- [elpa] scratch/org-contacts-rebased c0ebd3a 055/118: contrib/lisp/org-contacts: Allow org links in properties, Stefan Monnier, 2021/11/12
- [elpa] scratch/org-contacts-rebased 1b6cff5 026/118: contrib/lisp/org-contacts.el: Fix indentation of the file, Stefan Monnier, 2021/11/12
- [elpa] scratch/org-contacts-rebased dcd8af9 028/118: Merge branch 'maint', Stefan Monnier, 2021/11/12
- [elpa] scratch/org-contacts-rebased 2d1ea82 046/118: contrib/lisp/org-contacts.el: Silence byte-compiler, Stefan Monnier, 2021/11/12
- [elpa] scratch/org-contacts-rebased 7c908e4 043/118: org-contacts.el: Fix or add docstrings, Stefan Monnier, 2021/11/12
- [elpa] scratch/org-contacts-rebased 02808bb 047/118: Let org-contacts.el has the ability which can export email-address list, Stefan Monnier, 2021/11/12
- [elpa] scratch/org-contacts-rebased 927e7c7 035/118: org-contacts.el: Check if the database need a refresh in a dedicated function, Stefan Monnier, 2021/11/12
- [elpa] scratch/org-contacts-rebased e86b83d 036/118: org-contacts.el: Started to silent byte-compiler, Stefan Monnier, 2021/11/12
- [elpa] scratch/org-contacts-rebased c08b676 032/118: Add caching mecanism,
Stefan Monnier <=
- [elpa] scratch/org-contacts-rebased 543f2c5 045/118: contrib/lisp/org-contacts.el: Remove calls to cl functions, Stefan Monnier, 2021/11/12
- [elpa] scratch/org-contacts-rebased d7412d5 054/118: contrib/lisp/org-contacts: Fix two typos in comments, Stefan Monnier, 2021/11/12
- [elpa] scratch/org-contacts-rebased 2f0d7e9 002/118: org-contacts: make Gnus usage optional, Stefan Monnier, 2021/11/12
- [elpa] scratch/org-contacts-rebased ad7f57a 023/118: Fix error messages: don't use a dot at the end, Stefan Monnier, 2021/11/12
- [elpa] scratch/org-contacts-rebased 5526110 018/118: Merge branch 'origin-maint', Stefan Monnier, 2021/11/12
- [elpa] scratch/org-contacts-rebased 68918fc 034/118: org-contacts: Fix Agenda format., Stefan Monnier, 2021/11/12
- [elpa] scratch/org-contacts-rebased 85b506b 031/118: contrib/lisp/org-contacts.el: Delete trailing whitespaces, Stefan Monnier, 2021/11/12
- [elpa] scratch/org-contacts-rebased 30a76d5 038/118: org-contacts.el: Rename a function to follow emacs-lisp coding conventions, Stefan Monnier, 2021/11/12
- [elpa] scratch/org-contacts-rebased 57a9545 041/118: contrib/lisp/org-contacts.el: Fix compiler warnings., Stefan Monnier, 2021/11/12
- [elpa] scratch/org-contacts-rebased f4f5ff3 050/118: org-contacts.el (org-contacts-export-as-vcard): Don't use non-existent function `org-install-letbind', Stefan Monnier, 2021/11/12