[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/ebdb 825c4cc 112/350: Simplify the structure of ebdb-or
From: |
Eric Abrahamsen |
Subject: |
[elpa] externals/ebdb 825c4cc 112/350: Simplify the structure of ebdb-org-hashtable |
Date: |
Mon, 14 Aug 2017 11:46:17 -0400 (EDT) |
branch: externals/ebdb
commit 825c4ccb949d0eed9a0542a88cf6f6a1924aa620
Author: Eric Abrahamsen <address@hidden>
Commit: Eric Abrahamsen <address@hidden>
Simplify the structure of ebdb-org-hashtable
* ebdb.el (ebdb-init-field, ebdb-delete-field): These field-role
methods cache role information in ebdb-org-hashtable. The hash
entries used to be more complex, because roles originally didn't
store their record's uuid. They do now, so the entries can be much
simplified: simply a list of role fields, keyed to organizations'
uuids.
(ebdb-delete-record, ebdb-record-insert-field): Change access
accordingly.
(ebdb-record-add-org-role): Turn this into a method.
* ebdb-format.el (ebdb-fmt-collect-fields): Change access accordingly.
---
ebdb-format.el | 2 +-
ebdb.el | 67 +++++++++++++++++++++++-----------------------------------
2 files changed, 27 insertions(+), 42 deletions(-)
diff --git a/ebdb-format.el b/ebdb-format.el
index 2461afa..1fcc5b9 100644
--- a/ebdb-format.el
+++ b/ebdb-format.el
@@ -305,7 +305,7 @@ which formats them appropriately."
(memq 'ebdb-field-role include)
(null (memq 'ebdb-field-role exclude))))
(dolist (r roles)
- (push (cdr r) field-list)))
+ (push r field-list)))
(cl-call-next-method fmt record field-list))))
(cl-defmethod ebdb-fmt-sort-fields ((fmt ebdb-formatter)
diff --git a/ebdb.el b/ebdb.el
index 3bea000..97400a8 100644
--- a/ebdb.el
+++ b/ebdb.el
@@ -953,19 +953,20 @@ first one."
(when record
(let* ((org-uuid (slot-value role 'org-uuid))
(org (ebdb-gethash org-uuid 'uuid))
- (org-string (if org
- (ebdb-string (slot-value org 'name))
+ (org-string (if org (ebdb-record-name org)
"record not loaded"))
;; TODO: Guard against org-entry not being found.
(org-entry (gethash org-uuid ebdb-org-hashtable))
(record-uuid (ebdb-record-uuid record))
- (role-mail (slot-value role 'mail))
- new-org-entry exists-p)
- ;; TODO: We shouldn't really be doing this here, because setting
- ;; the slot value would mean the record/database should be set
- ;; to dirty, which it isn't necessarily, at this point.
- ;; Instead, `ebdb-read' should accept the record as an argument,
- ;; and this should be done in that method instead.
+ (role-mail (slot-value role 'mail)))
+ ;; Setting the 'record-uuid slot value when it wasn't set before
+ ;; technically means that the record is now "dirty". That's
+ ;; okay in our current database implementation, because
+ ;; `ebdb-record-insert-field' first calls
+ ;; `ebdb-db-add-record-field', which sets the record "dirty",
+ ;; and then calls this `ebdb-init' method -- ie, record is
+ ;; "dirty" when we get here. Theoretically, however, nothing in
+ ;; `ebdb-init-field' should change a record's slots.
(unless (slot-value role 'record-uuid)
(setf (slot-value role 'record-uuid) record-uuid))
(object-add-to-list (ebdb-record-cache record) 'organizations org-string)
@@ -973,20 +974,9 @@ first one."
(when (and role-mail (slot-value role-mail 'mail))
(ebdb-init-field role-mail record))
;; Make sure this role is in the `ebdb-org-hashtable'.
- (unless (and org-entry
- (dolist (pair org-entry exists-p)
- (if (and (string= record-uuid (car pair))
- (string= (slot-value (cdr pair) 'object-name)
- (slot-value role 'object-name)))
- (setq exists-p t)
- (push pair new-org-entry))))
- ;; TODO: It's no longer necessary to record the record-uuid
- ;; along with the role, as the uuid is recorded in a slot on
- ;; the role.
- (push (cons record-uuid role) new-org-entry))
- (puthash org-uuid new-org-entry ebdb-org-hashtable)))
- (when (slot-value role 'mail)
- (ebdb-init-field (slot-value role 'mail) record))
+ (unless (member role org-entry)
+ (push role org-entry))
+ (puthash org-uuid org-entry ebdb-org-hashtable)))
(cl-call-next-method))
(cl-defmethod ebdb-delete-field ((role ebdb-field-role) &optional record
unload)
@@ -995,22 +985,15 @@ first one."
(org (ebdb-gethash org-uuid 'uuid))
(org-string
(if org
- (slot-value org 'name)
+ (ebdb-record-name org)
"bogus"))
(org-entry (gethash org-uuid ebdb-org-hashtable))
- (record-uuid (ebdb-record-uuid record))
- record-entry new-org-entry)
- (while (setq record-entry (pop org-entry))
- ;; The assumption being made here is that
- ;; record+organization+role-label combinations must be unique.
- ;; A record can have multiple roles at an organization, but
- ;; those roles must have different labels.
- (unless (and (string= (car record-entry) record-uuid)
- (string= (slot-value role 'object-name)
- (slot-value (cdr record-entry) 'object-name)))
- (push record-entry new-org-entry)))
- (puthash org-uuid new-org-entry ebdb-org-hashtable)
- (when (null (assoc-string record-uuid org-entry))
+ (record-uuid (ebdb-record-uuid record)))
+ (setq org-entry (delete role org-entry))
+ (if org-entry
+ (puthash org-uuid org-entry ebdb-org-hashtable)
+ (remhash org-uuid ebdb-org-hashtable))
+ (when (null (assoc-string record-uuid (object-assoc-list 'record-uuid
org-entry)))
;; RECORD no long has any roles at ORG.
(object-remove-from-list (ebdb-record-cache record) 'organizations
org-string))))
(when (slot-value role 'mail)
@@ -2414,8 +2397,8 @@ priority."
(yes-or-no-p (format "Delete all roles associated with %s"
(ebdb-string org))))
(dolist (r org-entry)
- (setq record (ebdb-gethash (car r) 'uuid))
- (ebdb-record-delete-field record 'organizations (cdr r))))
+ (setq record (ebdb-gethash (slot-value r 'record-uuid) 'uuid))
+ (ebdb-record-delete-field record 'organizations r)))
(cl-call-next-method)))
(cl-defmethod ebdb-string ((record ebdb-record-organization))
@@ -2516,7 +2499,7 @@ Currently only works for mail fields."
(let ((roles (gethash (ebdb-record-uuid org) ebdb-org-hashtable))
rec)
(dolist (r roles)
- (setq rec (ebdb-gethash (car r) 'uuid))
+ (setq rec (ebdb-gethash (slot-value r 'record-uuid) 'uuid))
(ebdb-record-adopt-role-fields rec org t))))
(cl-defmethod ebdb-record-change-field ((_record ebdb-record-organization)
@@ -2552,7 +2535,9 @@ appropriate person record."
(field ebdb-field-role))
(ebdb-gethash (slot-value field 'record-uuid) 'uuid))
-(defun ebdb-record-add-org-role (record org &optional mail fields)
+(defmethod ebdb-record-add-org-role ((record ebdb-record-person)
+ (org ebdb-record-organization)
+ &optional mail fields)
"Convenience function for creating a role relationship between RECORD and
ORG.
MAIL and/or FIELDS, if present, should be a list of field
- [elpa] externals/ebdb 4263d5b 090/350: Fix the reload process, (continued)
- [elpa] externals/ebdb 4263d5b 090/350: Fix the reload process, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb dd4f251 098/350: Split off ebdb-record-field for field classes, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 8c20202 103/350: Update company-ebdb to work with new search style, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 5ec40d5 102/350: Add sections on searching and record marking to manual, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 7da77f4 089/350: Expand ebdb-with-record-edits, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 8312ea4 109/350: Allow company-ebdb to work in notmuch-message-mode as well, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb dcb7dbc 104/350: Change default keybindings in Gnus, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 9ac0f0f 111/350: Searching on empty strings should happen in field-search method, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb c43e39b 097/350: Another round of compiler-inspired fixes, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 40df5bc 114/350: Remove ebdb-new-mails-primary, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 825c4cc 112/350: Simplify the structure of ebdb-org-hashtable,
Eric Abrahamsen <=
- [elpa] externals/ebdb c0979b0 135/350: Typo in ebdb-mua-check-header, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 1219b93 100/350: Rework *EBDB* buffer searching, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 80ef19d 108/350: Make ebdb-search-read and ebdb-search-field into generics, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 6c85728 116/350: Manual and README additions, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 4688493 125/350: Wrap ebdb-parse in save-match-data, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 587ebbc 129/350: Use ebdb-prompt-for-record in org link completion, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 8f82b0f 121/350: Complete changes from ed3e270, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 9edc54f 120/350: Merge snarf branch, basic framework of snarfing in place, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 61b533c 127/350: Simplify ebdb-record-field for strings, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb b610b96 138/350: ebdb-record-search can accept symbols for search type, Eric Abrahamsen, 2017/08/14