[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/ebdb 1a31515 274/350: Fixes to record loading
From: |
Eric Abrahamsen |
Subject: |
[elpa] externals/ebdb 1a31515 274/350: Fixes to record loading |
Date: |
Mon, 14 Aug 2017 11:46:52 -0400 (EDT) |
branch: externals/ebdb
commit 1a3151512475b00bd8476d210a099ba0acf479b3
Author: Eric Abrahamsen <address@hidden>
Commit: Eric Abrahamsen <address@hidden>
Fixes to record loading
* ebdb.el (ebdb-db-add-record): Don't call `ebdb-db-load-records'
here. It seemed like a neat way to re-use the loading procedure, but
the uuid check will raise an error with the record's own self as a
duplicate. There's no need to use something that deep anyway, this
method should be kept straightforward. This fixes moving/copying
records between databases.
(ebdb-delete-record, ebdb-init-record): Clean up code in here
somewhat.
* ebdb-test.el (ebdb-test-database-2): Add a second test database.
(ebdb-test-with-database): Fix dumb macro mistake.
(ebdb-load-record-multiple-databases): Test multiple
---
ebdb-test.el | 28 ++++++++++++++++++++++------
ebdb.el | 30 ++++++++++++++----------------
2 files changed, 36 insertions(+), 22 deletions(-)
diff --git a/ebdb-test.el b/ebdb-test.el
index 7bc43cc..cbedfad 100644
--- a/ebdb-test.el
+++ b/ebdb-test.el
@@ -42,7 +42,7 @@
;; Save sets sync-time.
(ebdb-db-save ,(car db-and-filename))
;; Load adds to `ebdb-db-list'.
- (ebdb-db-load db)
+ (ebdb-db-load ,(car db-and-filename))
(unwind-protect
(progn
,@body)
@@ -61,6 +61,11 @@
"emacs-ebdb-test-db-1-"
temporary-file-directory)))
+(defvar ebdb-test-database-2 (make-temp-name
+ (expand-file-name
+ "emacs-ebdb-test-db-2-"
+ temporary-file-directory)))
+
(ert-deftest ebdb-make-database ()
"Make a database and save it to disk."
(ebdb-test-with-database (db ebdb-test-database-1)
@@ -77,10 +82,9 @@
(ert-deftest ebdb-database-unsynced ()
"Make sure database knows it's unsynced."
(ebdb-test-with-database (db ebdb-test-database-1)
- ;; Sync-time doesn't get updated until we load it.
- (ebdb-db-load db)
- ;; Apparently the two calls are too close together to register a
- ;; difference in time, which I find weird.
+ ;; Apparently the call to `ebdb-db-load' and the test are too
+ ;; close together to register a difference in time, which I find
+ ;; weird.
(sit-for 0.1)
(append-to-file "\n;; Junk string" nil (slot-value db 'file))
(should (ebdb-db-unsynced db))))
@@ -97,7 +101,19 @@
(let ((rec (make-instance 'ebdb-record-person)))
(should (null (ebdb-record-uuid rec)))
(ebdb-db-add-record db rec)
- (should (stringp (ebdb-record-uuid rec)))))))
+ (should (stringp (ebdb-record-uuid rec)))
+ (should (ebdb-gethash (ebdb-record-uuid rec) 'uuid))))))
+
+(ert-deftest ebdb-load-record-multiple-databases ()
+ "Test loading of a record into multiple databases."
+ (ebdb-test-with-records
+ (ebdb-test-with-database (db1 ebdb-test-database-1)
+ (ebdb-test-with-database (db2 ebdb-test-database-2)
+ (let ((rec (make-instance 'ebdb-record-person)))
+ (ebdb-db-add-record db1 rec)
+ (ebdb-db-add-record db2 rec)
+ (should (= 1 (length ebdb-record-tracker)))
+ (should (equal rec (ebdb-gethash (ebdb-record-uuid rec) 'uuid))))))))
;; Test adding, deleting and changing fields.
diff --git a/ebdb.el b/ebdb.el
index b5edf24..d0632fe 100644
--- a/ebdb.el
+++ b/ebdb.el
@@ -2447,23 +2447,19 @@ priority."
class (plist-put slots :name name))))
(cl-defmethod ebdb-init-record ((record ebdb-record-person))
- (ebdb-init-field (slot-value record 'name) record)
- (dolist (aka (slot-value record 'aka))
- (ebdb-init-field aka record))
- (dolist (relation (slot-value record 'relations))
- (ebdb-init-field relation record))
- (dolist (role (slot-value record 'organizations))
- (ebdb-init-field role record))
+ (with-slots (name aka relations organizations) record
+ (when name
+ (ebdb-init-field name record))
+ (dolist (f (append aka relations organizations))
+ (ebdb-init-field f record)))
(cl-call-next-method))
(cl-defmethod ebdb-delete-record ((record ebdb-record-person) &optional _db
unload)
- (ebdb-delete-field (slot-value record 'name) record unload)
- (dolist (a (slot-value record 'aka))
- (ebdb-delete-field a record unload))
- (dolist (r (slot-value record 'relations))
- (ebdb-delete-field r record unload))
- (dolist (o (slot-value record 'organizations))
- (ebdb-delete-field o record unload))
+ (with-slots (name aka relations organizations) record
+ (when name
+ (ebdb-delete-field name record unload))
+ (dolist (f (append aka relations organizations))
+ (ebdb-delete-field f record unload)))
(cl-call-next-method))
(cl-defmethod ebdb-merge ((left ebdb-record-person)
@@ -3246,9 +3242,10 @@ the persistent save, or allow them to propagate."
(setf (slot-value record 'uuid)
(make-instance
'ebdb-field-uuid
- :uuid (ebdb-make-uuid (slot-value db 'uuid-prefix)))))
+ :uuid (ebdb-make-uuid (slot-value db 'uuid-prefix))))
+ (ebdb-puthash (ebdb-record-uuid record) record))
(object-add-to-list db 'records record)
- (ebdb-db-load-records db (list record))
+ (object-add-to-list (ebdb-record-cache record) 'database db)
(setf (slot-value db 'dirty) t)
;; TODO: Is there any need to sort the DB's records after insertion?
;; What about sorting ebdb-record-tracker?
@@ -3258,6 +3255,7 @@ the persistent save, or allow them to propagate."
(object-remove-from-list db 'records record)
(object-remove-from-list (ebdb-record-cache record)
'database db)
+ (setf (slot-value db 'dirty) t)
record)
(cl-defmethod ebdb-db-add-record-field :before ((db ebdb-db) record _slot
_field)
- [elpa] externals/ebdb f44a797 286/350: New function ebdb-mua-in-ebdb-buffer, (continued)
- [elpa] externals/ebdb f44a797 286/350: New function ebdb-mua-in-ebdb-buffer, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 4ce353e 237/350: Migrate more search routines to the ebdb-search-display thing, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 7040cad 247/350: Expand ebdb-helm to complete on mails as well, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb a6bc423 249/350: Remove unused customization groups, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 4ded53d 250/350: All vCard lines should be delimited with CRLF, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb a776d37 248/350: Don't use copy-sequence plus add-text-properties on strings, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 96b113d 251/350: New functions for folding/unfolding long vCard lines, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb b52cdc0 265/350: Record-insert|delete-field methods can find their own slots, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb fcee6ab 267/350: Protect against no current record when redisplaying, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb f3b9525 269/350: Temporarily abandon having record-change-name accept strings, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 1a31515 274/350: Fixes to record loading,
Eric Abrahamsen <=
- [elpa] externals/ebdb 01262e3 277/350: Mark EBDB buffers as modified after edits, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb cc83f62 197/350: Add protection around ebdb-record-uuid, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 4f3db7f 195/350: Save match data around ebdb-parse-i18n, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb fcf0702 275/350: Mark EBDB buffers as unmodified after save, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 88f5e12 261/350: Fill out functionality of gnorb messages field, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb a81769c 272/350: Allow custom hash predicates, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb e80753a 264/350: Change ebdb-record-change-name to accept strings, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb d3e1485 283/350: Reinstate the notice record hook, and move notice-record method, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb d8bc159 290/350: Fairly embarrassing oversight in setting ebdb buffers modified, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb afe5495 279/350: Adjust indentation of multi-line field values, Eric Abrahamsen, 2017/08/14