[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/org-contacts d630e91dee 033/154: Add caching mecanism
From: |
ELPA Syncer |
Subject: |
[elpa] externals/org-contacts d630e91dee 033/154: Add caching mecanism |
Date: |
Fri, 9 Sep 2022 15:58:24 -0400 (EDT) |
branch: externals/org-contacts
commit d630e91dee767c991ffb984ddd72d1f2d3b3f93b
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 49bf4894d3..7af8c356a4 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] externals/org-contacts 8e9ac123b1 034/154: Do not complete when it's not necessary, (continued)
- [elpa] externals/org-contacts 8e9ac123b1 034/154: Do not complete when it's not necessary, ELPA Syncer, 2022/09/09
- [elpa] externals/org-contacts e516efacb6 037/154: Merge branch 'maint', ELPA Syncer, 2022/09/09
- [elpa] externals/org-contacts 93f982e3ba 030/154: Merge branch 'maint', ELPA Syncer, 2022/09/09
- [elpa] externals/org-contacts 23af13f11a 049/154: contrib/lisp/org-contacts.el: Silence byte-compiler, ELPA Syncer, 2022/09/09
- [elpa] externals/org-contacts bc11ab4130 053/154: org-contacts.el (org-contacts-export-as-vcard): Don't use non-existent function `org-install-letbind', ELPA Syncer, 2022/09/09
- [elpa] externals/org-contacts 9105e22251 066/154: contrib/lisp/org-contacts.el: Add a complex org-contacts template to the file header, ELPA Syncer, 2022/09/09
- [elpa] externals/org-contacts 4108493c9d 055/154: org-contacts.el , fix bugs about 'tel and 'note properties, ELPA Syncer, 2022/09/09
- [elpa] externals/org-contacts d6824ec3c2 069/154: org-contacts: use `org-' prefixed variants of cl functions, ELPA Syncer, 2022/09/09
- [elpa] externals/org-contacts fd0f42a1bc 075/154: Update copyright years again., ELPA Syncer, 2022/09/09
- [elpa] externals/org-contacts 5526110aac 018/154: Merge branch 'origin-maint', ELPA Syncer, 2022/09/09
- [elpa] externals/org-contacts d630e91dee 033/154: Add caching mecanism,
ELPA Syncer <=
- [elpa] externals/org-contacts 680dc1f24d 039/154: org-contacts.el: Started to silent byte-compiler, ELPA Syncer, 2022/09/09
- [elpa] externals/org-contacts 3f1509bfa2 035/154: org-contacts: Fix Agenda format., ELPA Syncer, 2022/09/09
- [elpa] externals/org-contacts abbf3a9a25 041/154: org-contacts.el: Rename a function to follow emacs-lisp coding conventions, ELPA Syncer, 2022/09/09
- [elpa] externals/org-contacts 5d5faa5e6b 051/154: org-contacts.el, add note property, ELPA Syncer, 2022/09/09
- [elpa] externals/org-contacts 9bd8101c56 059/154: contrib/lisp/org-contacts: Introduce the constant `org-contacts-property-values-separators', ELPA Syncer, 2022/09/09
- [elpa] externals/org-contacts beb76bf435 060/154: org-contacts: Use progress-reporter for cache update message, ELPA Syncer, 2022/09/09
- [elpa] externals/org-contacts 9d9246c0a5 072/154: Merge branch 'maint', ELPA Syncer, 2022/09/09
- [elpa] externals/org-contacts 66e23e6403 008/154: org-contacts: added VCard 3.0 exporter and ADDRESS field, ELPA Syncer, 2022/09/09
- [elpa] externals/org-contacts 4d5b508f0f 007/154: org-contacts: check that completion-at-point-functions is bound, ELPA Syncer, 2022/09/09
- [elpa] externals/org-contacts 531d67a715 014/154: Fix Emacs 24 compatibility issue with Emacs 24, ELPA Syncer, 2022/09/09