moved to using in keys rather than class names in the referece_map table
svn: r5575
This commit is contained in:
parent
d35b4ea7b0
commit
9f891c2913
@ -1,3 +1,11 @@
|
||||
2005-12-17 Richard Taylor <rjt-gramps@thegrindstone.me.uk>
|
||||
* src/GrampsBSDDB.py: reference_map now uses keys rather
|
||||
than class names
|
||||
* src/GrampsDbBase.py: reference_map now uses keys rather
|
||||
than class names
|
||||
* test/GrampsDbBase_Test.py: reference_map now uses keys rather
|
||||
than class names
|
||||
|
||||
2005-12-17 Richard Taylor <rjt-gramps@thegrindstone.me.uk>
|
||||
* src/GrampsDbBase.py: fixed UNDO buffer issue
|
||||
* test/GrampsDbBase_Test.py: improved performance test
|
||||
|
@ -463,7 +463,7 @@ class GrampsBSDDB(GrampsDbBase):
|
||||
# so we need the first tuple to give us the type to compare
|
||||
|
||||
data = cPickle.loads(data)
|
||||
if include_classes == None or data[0][0] in include_classes:
|
||||
if include_classes == None or KEY_TO_CLASS_MAP[data[0][0]] in include_classes:
|
||||
yield data[0]
|
||||
|
||||
ret = referenced_cur.next_dup()
|
||||
@ -500,8 +500,7 @@ class GrampsBSDDB(GrampsDbBase):
|
||||
|
||||
primary_cur.close()
|
||||
|
||||
def _update_reference_map(self, obj, class_name):
|
||||
|
||||
def _update_reference_map(self, obj):
|
||||
# Add references to the reference_map for all primary object referenced
|
||||
# from the primary object 'obj' or any of its secondary objects.
|
||||
|
||||
@ -538,7 +537,9 @@ class GrampsBSDDB(GrampsDbBase):
|
||||
# Looks like there is a bug in the set() and next_dup() methods
|
||||
# because they do not run the data through cPickle.loads before
|
||||
# returning it, so we have to here.
|
||||
existing_references.add(cPickle.loads(data)[1])
|
||||
existing_reference = cPickle.loads(data)[1]
|
||||
existing_references.add((KEY_TO_CLASS_MAP[existing_reference[0]],
|
||||
existing_reference[1]))
|
||||
ret = primary_cur.next_dup()
|
||||
|
||||
primary_cur.close()
|
||||
@ -554,10 +555,11 @@ class GrampsBSDDB(GrampsDbBase):
|
||||
new_references = current_references.difference(existing_references)
|
||||
|
||||
# handle addition of new references
|
||||
|
||||
if len(new_references) > 0:
|
||||
for (ref_class_name,ref_handle) in new_references:
|
||||
self.reference_map[str((handle,ref_handle),)] = ((class_name,handle),
|
||||
(ref_class_name,ref_handle),)
|
||||
self.reference_map[str((handle,ref_handle),)] = ((CLASS_TO_KEY_MAP[obj.__class__.__name__],handle),
|
||||
(CLASS_TO_KEY_MAP[ref_class_name],ref_handle),)
|
||||
|
||||
# handle deletion of old references
|
||||
if len(no_longer_required_references) > 0:
|
||||
@ -612,7 +614,7 @@ class GrampsBSDDB(GrampsDbBase):
|
||||
obj = class_func()
|
||||
obj.unserialize(val)
|
||||
|
||||
self._update_reference_map(obj,primary_table_name)
|
||||
self._update_reference_map(obj)
|
||||
|
||||
data = cursor.next()
|
||||
|
||||
|
@ -74,6 +74,29 @@ MEDIA_COL_KEY = 'media_columns'
|
||||
REPOSITORY_COL_KEY = 'repository_columns'
|
||||
EVENT_COL_KEY = 'event_columns'
|
||||
|
||||
|
||||
# The following two dictionaries provide fast translation
|
||||
# between the primary class names and the keys used to reference
|
||||
# these classes in the database tables. Beware that changing
|
||||
# these maps or modifying the values of the keys will break
|
||||
# existing databases.
|
||||
|
||||
CLASS_TO_KEY_MAP = {Person.__name__: PERSON_KEY,
|
||||
Family.__name__: FAMILY_KEY,
|
||||
Source.__name__: SOURCE_KEY,
|
||||
Event.__name__: EVENT_KEY,
|
||||
MediaObject.__name__: MEDIA_KEY,
|
||||
Place.__name__: PLACE_KEY,
|
||||
Repository.__name__:REPOSITORY_KEY}
|
||||
|
||||
KEY_TO_CLASS_MAP = {PERSON_KEY: Person.__name__,
|
||||
FAMILY_KEY: Family.__name__,
|
||||
SOURCE_KEY: Source.__name__,
|
||||
EVENT_KEY: Event.__name__,
|
||||
MEDIA_KEY: MediaObject.__name__,
|
||||
PLACE_KEY: Place.__name__,
|
||||
REPOSITORY_KEY: Repository.__name__}
|
||||
|
||||
_sigbase = ('person', 'family', 'source', 'event',
|
||||
'media', 'place', 'repository')
|
||||
|
||||
@ -342,7 +365,7 @@ class GrampsDbBase(GrampsDBCallback.GrampsDBCallback):
|
||||
as part of the transaction.
|
||||
"""
|
||||
|
||||
self._update_reference_map(person,'Person')
|
||||
self._update_reference_map(person)
|
||||
|
||||
old_data = self._commit_base(
|
||||
person, self.person_map, PERSON_KEY, transaction.person_update,
|
||||
@ -367,7 +390,7 @@ class GrampsDbBase(GrampsDBCallback.GrampsDBCallback):
|
||||
as part of the transaction.
|
||||
"""
|
||||
|
||||
self._update_reference_map(obj,'MediaObject')
|
||||
self._update_reference_map(obj)
|
||||
|
||||
self._commit_base(obj, self.media_map, MEDIA_KEY,
|
||||
transaction.media_update, transaction.media_add,
|
||||
@ -379,7 +402,7 @@ class GrampsDbBase(GrampsDBCallback.GrampsDBCallback):
|
||||
as part of the transaction.
|
||||
"""
|
||||
|
||||
self._update_reference_map(source,'Source')
|
||||
self._update_reference_map(source)
|
||||
|
||||
self._commit_base(source, self.source_map, SOURCE_KEY,
|
||||
transaction.source_update, transaction.source_add,
|
||||
@ -391,7 +414,7 @@ class GrampsDbBase(GrampsDBCallback.GrampsDBCallback):
|
||||
as part of the transaction.
|
||||
"""
|
||||
|
||||
self._update_reference_map(place,'Place')
|
||||
self._update_reference_map(place)
|
||||
|
||||
self._commit_base(place, self.place_map, PLACE_KEY,
|
||||
transaction.place_update, transaction.place_add,
|
||||
@ -413,7 +436,7 @@ class GrampsDbBase(GrampsDBCallback.GrampsDBCallback):
|
||||
as part of the transaction.
|
||||
"""
|
||||
|
||||
self._update_reference_map(event,'Event')
|
||||
self._update_reference_map(event)
|
||||
|
||||
self._commit_base(event, self.event_map, EVENT_KEY,
|
||||
transaction.event_update, transaction.event_add,
|
||||
@ -425,7 +448,7 @@ class GrampsDbBase(GrampsDBCallback.GrampsDBCallback):
|
||||
as part of the transaction.
|
||||
"""
|
||||
|
||||
self._update_reference_map(family,'Family')
|
||||
self._update_reference_map(family)
|
||||
|
||||
self._commit_base(family, self.family_map, FAMILY_KEY,
|
||||
transaction.family_update, transaction.family_add,
|
||||
@ -440,7 +463,7 @@ class GrampsDbBase(GrampsDBCallback.GrampsDBCallback):
|
||||
as part of the transaction.
|
||||
"""
|
||||
|
||||
self._update_reference_map(repository,'Repository')
|
||||
self._update_reference_map(repository)
|
||||
|
||||
self._commit_base(repository, self.repository_map, REPOSITORY_KEY,
|
||||
transaction.repository_update, transaction.repository_add,
|
||||
|
@ -153,7 +153,7 @@ class ReferenceMapTest (unittest.TestCase):
|
||||
references = [ ref for ref in self._db.find_backlink_handles(source.get_handle()) ]
|
||||
|
||||
assert len(references) == 1
|
||||
assert references[0] == ('Person',person.get_handle())
|
||||
assert references[0] == (GrampsBSDDB.CLASS_TO_KEY_MAP[RelLib.Person.__name__],person.get_handle())
|
||||
|
||||
def test_delete_primary(self):
|
||||
"""check that deleting a primary will remove the backreferences
|
||||
@ -181,7 +181,7 @@ class ReferenceMapTest (unittest.TestCase):
|
||||
# unhook the reference_map update function so that we
|
||||
# can insert some records without the reference_map being updated.
|
||||
update_method = self._db._update_reference_map
|
||||
self._db._update_reference_map = lambda x,y: 1
|
||||
self._db._update_reference_map = lambda x: 1
|
||||
|
||||
# Insert a person/source pair.
|
||||
source = self._add_source()
|
||||
|
Loading…
Reference in New Issue
Block a user