Reworked backend Cursors; don't emit changes when changing in batch mode
This commit is contained in:
parent
6da7f78cba
commit
1118ce449c
0
gramps/plugins/database/__init__.py
Normal file
0
gramps/plugins/database/__init__.py
Normal file
File diff suppressed because it is too large
Load Diff
@ -130,27 +130,33 @@ class Cursor(object):
|
|||||||
def __init__(self, map, func):
|
def __init__(self, map, func):
|
||||||
self.map = map
|
self.map = map
|
||||||
self.func = func
|
self.func = func
|
||||||
|
self._iter = self.__iter__()
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
return self
|
return self
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
return self.__next__()
|
|
||||||
def __next__(self):
|
|
||||||
for item in self.map.keys():
|
for item in self.map.keys():
|
||||||
yield (bytes(item, "utf-8"), self.func(item))
|
yield (bytes(item, "utf-8"), self.func(item))
|
||||||
|
def __next__(self):
|
||||||
|
try:
|
||||||
|
return self._iter.__next__()
|
||||||
|
except StopIteration:
|
||||||
|
return None
|
||||||
def __exit__(self, *args, **kwargs):
|
def __exit__(self, *args, **kwargs):
|
||||||
pass
|
pass
|
||||||
def iter(self):
|
def iter(self):
|
||||||
for item in self.map.keys():
|
for item in self.map.keys():
|
||||||
yield (bytes(item, "utf-8"), self.func(item))
|
yield (bytes(item, "utf-8"), self.func(item))
|
||||||
yield None
|
|
||||||
def first(self):
|
def first(self):
|
||||||
self._iter = self.__iter__()
|
self._iter = self.__iter__()
|
||||||
return self.next()
|
try:
|
||||||
|
return next(self._iter)
|
||||||
|
except:
|
||||||
|
return
|
||||||
def next(self):
|
def next(self):
|
||||||
try:
|
try:
|
||||||
return next(self._iter)
|
return next(self._iter)
|
||||||
except:
|
except:
|
||||||
return None
|
return
|
||||||
def close(self):
|
def close(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -1099,6 +1105,7 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
|
|||||||
return obj.handle
|
return obj.handle
|
||||||
|
|
||||||
def commit_person(self, person, trans, change_time=None):
|
def commit_person(self, person, trans, change_time=None):
|
||||||
|
if not trans.batch:
|
||||||
if person.handle in self.person_map:
|
if person.handle in self.person_map:
|
||||||
self.emit("person-update", ([person.handle],))
|
self.emit("person-update", ([person.handle],))
|
||||||
else:
|
else:
|
||||||
@ -1106,6 +1113,7 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
|
|||||||
self.person_map[person.handle] = person
|
self.person_map[person.handle] = person
|
||||||
|
|
||||||
def commit_family(self, family, trans, change_time=None):
|
def commit_family(self, family, trans, change_time=None):
|
||||||
|
if not trans.batch:
|
||||||
if family.handle in self.family_map:
|
if family.handle in self.family_map:
|
||||||
self.emit("family-update", ([family.handle],))
|
self.emit("family-update", ([family.handle],))
|
||||||
else:
|
else:
|
||||||
@ -1113,6 +1121,7 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
|
|||||||
self.family_map[family.handle] = family
|
self.family_map[family.handle] = family
|
||||||
|
|
||||||
def commit_citation(self, citation, trans, change_time=None):
|
def commit_citation(self, citation, trans, change_time=None):
|
||||||
|
if not trans.batch:
|
||||||
if citation.handle in self.citation_map:
|
if citation.handle in self.citation_map:
|
||||||
self.emit("citation-update", ([citation.handle],))
|
self.emit("citation-update", ([citation.handle],))
|
||||||
else:
|
else:
|
||||||
@ -1120,6 +1129,7 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
|
|||||||
self.citation_map[citation.handle] = citation
|
self.citation_map[citation.handle] = citation
|
||||||
|
|
||||||
def commit_source(self, source, trans, change_time=None):
|
def commit_source(self, source, trans, change_time=None):
|
||||||
|
if not trans.batch:
|
||||||
if source.handle in self.source_map:
|
if source.handle in self.source_map:
|
||||||
self.emit("source-update", ([source.handle],))
|
self.emit("source-update", ([source.handle],))
|
||||||
else:
|
else:
|
||||||
@ -1127,6 +1137,7 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
|
|||||||
self.source_map[source.handle] = source
|
self.source_map[source.handle] = source
|
||||||
|
|
||||||
def commit_repository(self, repository, trans, change_time=None):
|
def commit_repository(self, repository, trans, change_time=None):
|
||||||
|
if not trans.batch:
|
||||||
if repository.handle in self.repository_map:
|
if repository.handle in self.repository_map:
|
||||||
self.emit("repository-update", ([repository.handle],))
|
self.emit("repository-update", ([repository.handle],))
|
||||||
else:
|
else:
|
||||||
@ -1134,6 +1145,7 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
|
|||||||
self.repository_map[repository.handle] = repository
|
self.repository_map[repository.handle] = repository
|
||||||
|
|
||||||
def commit_note(self, note, trans, change_time=None):
|
def commit_note(self, note, trans, change_time=None):
|
||||||
|
if not trans.batch:
|
||||||
if note.handle in self.note_map:
|
if note.handle in self.note_map:
|
||||||
self.emit("note-update", ([note.handle],))
|
self.emit("note-update", ([note.handle],))
|
||||||
else:
|
else:
|
||||||
@ -1141,6 +1153,7 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
|
|||||||
self.note_map[note.handle] = note
|
self.note_map[note.handle] = note
|
||||||
|
|
||||||
def commit_place(self, place, trans, change_time=None):
|
def commit_place(self, place, trans, change_time=None):
|
||||||
|
if not trans.batch:
|
||||||
if place.handle in self.place_map:
|
if place.handle in self.place_map:
|
||||||
self.emit("place-update", ([place.handle],))
|
self.emit("place-update", ([place.handle],))
|
||||||
else:
|
else:
|
||||||
@ -1148,6 +1161,7 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
|
|||||||
self.place_map[place.handle] = place
|
self.place_map[place.handle] = place
|
||||||
|
|
||||||
def commit_event(self, event, trans, change_time=None):
|
def commit_event(self, event, trans, change_time=None):
|
||||||
|
if not trans.batch:
|
||||||
if event.handle in self.event_map:
|
if event.handle in self.event_map:
|
||||||
self.emit("event-update", ([event.handle],))
|
self.emit("event-update", ([event.handle],))
|
||||||
else:
|
else:
|
||||||
@ -1155,6 +1169,7 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
|
|||||||
self.event_map[event.handle] = event
|
self.event_map[event.handle] = event
|
||||||
|
|
||||||
def commit_tag(self, tag, trans, change_time=None):
|
def commit_tag(self, tag, trans, change_time=None):
|
||||||
|
if not trans.batch:
|
||||||
if tag.handle in self.tag_map:
|
if tag.handle in self.tag_map:
|
||||||
self.emit("tag-update", ([tag.handle],))
|
self.emit("tag-update", ([tag.handle],))
|
||||||
else:
|
else:
|
||||||
@ -1162,6 +1177,7 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
|
|||||||
self.tag_map[tag.handle] = tag
|
self.tag_map[tag.handle] = tag
|
||||||
|
|
||||||
def commit_media_object(self, media, transaction, change_time=None):
|
def commit_media_object(self, media, transaction, change_time=None):
|
||||||
|
if not trans.batch:
|
||||||
if media.handle in self.media_map:
|
if media.handle in self.media_map:
|
||||||
self.emit("media-update", ([media.handle],))
|
self.emit("media-update", ([media.handle],))
|
||||||
else:
|
else:
|
||||||
|
@ -127,13 +127,17 @@ class Cursor(object):
|
|||||||
def __init__(self, model, func):
|
def __init__(self, model, func):
|
||||||
self.model = model
|
self.model = model
|
||||||
self.func = func
|
self.func = func
|
||||||
|
self._iter = self.__iter__()
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
return self
|
return self
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
return self.__next__()
|
|
||||||
def __next__(self):
|
|
||||||
for item in self.model.all():
|
for item in self.model.all():
|
||||||
yield (bytes(item.handle, "utf-8"), self.func(item.handle))
|
yield (bytes(item.handle, "utf-8"), self.func(item.handle))
|
||||||
|
def __next__(self):
|
||||||
|
try:
|
||||||
|
return self._iter.__next__()
|
||||||
|
except StopIteration:
|
||||||
|
return None
|
||||||
def __exit__(self, *args, **kwargs):
|
def __exit__(self, *args, **kwargs):
|
||||||
pass
|
pass
|
||||||
def iter(self):
|
def iter(self):
|
||||||
@ -142,7 +146,10 @@ class Cursor(object):
|
|||||||
yield None
|
yield None
|
||||||
def first(self):
|
def first(self):
|
||||||
self._iter = self.__iter__()
|
self._iter = self.__iter__()
|
||||||
return self.next()
|
try:
|
||||||
|
return next(self._iter)
|
||||||
|
except:
|
||||||
|
return
|
||||||
def next(self):
|
def next(self):
|
||||||
try:
|
try:
|
||||||
return next(self._iter)
|
return next(self._iter)
|
||||||
@ -1494,6 +1501,7 @@ class DbDjango(DbWriteBase, DbReadBase, UpdateCallback, Callback):
|
|||||||
items[0].delete()
|
items[0].delete()
|
||||||
self.dji.add_person(person.serialize())
|
self.dji.add_person(person.serialize())
|
||||||
self.dji.add_person_detail(person.serialize())
|
self.dji.add_person_detail(person.serialize())
|
||||||
|
if not trans.batch:
|
||||||
if items.count() > 0:
|
if items.count() > 0:
|
||||||
self.emit("person-update", ([person.handle],))
|
self.emit("person-update", ([person.handle],))
|
||||||
else:
|
else:
|
||||||
@ -1509,6 +1517,7 @@ class DbDjango(DbWriteBase, DbReadBase, UpdateCallback, Callback):
|
|||||||
items[0].delete()
|
items[0].delete()
|
||||||
self.dji.add_family(family.serialize())
|
self.dji.add_family(family.serialize())
|
||||||
self.dji.add_family_detail(family.serialize())
|
self.dji.add_family_detail(family.serialize())
|
||||||
|
if not trans.batch:
|
||||||
if items.count() > 0:
|
if items.count() > 0:
|
||||||
self.emit("family-update", ([family.handle],))
|
self.emit("family-update", ([family.handle],))
|
||||||
else:
|
else:
|
||||||
@ -1524,6 +1533,7 @@ class DbDjango(DbWriteBase, DbReadBase, UpdateCallback, Callback):
|
|||||||
items[0].delete()
|
items[0].delete()
|
||||||
self.dji.add_citation(citation.serialize())
|
self.dji.add_citation(citation.serialize())
|
||||||
self.dji.add_citation_detail(citation.serialize())
|
self.dji.add_citation_detail(citation.serialize())
|
||||||
|
if not trans.batch:
|
||||||
if items.count() > 0:
|
if items.count() > 0:
|
||||||
self.emit("citation-update", ([citation.handle],))
|
self.emit("citation-update", ([citation.handle],))
|
||||||
else:
|
else:
|
||||||
@ -1539,6 +1549,7 @@ class DbDjango(DbWriteBase, DbReadBase, UpdateCallback, Callback):
|
|||||||
items[0].delete()
|
items[0].delete()
|
||||||
self.dji.add_source(source.serialize())
|
self.dji.add_source(source.serialize())
|
||||||
self.dji.add_source_detail(source.serialize())
|
self.dji.add_source_detail(source.serialize())
|
||||||
|
if not trans.batch:
|
||||||
if items.count() > 0:
|
if items.count() > 0:
|
||||||
self.emit("source-update", ([source.handle],))
|
self.emit("source-update", ([source.handle],))
|
||||||
else:
|
else:
|
||||||
@ -1554,6 +1565,7 @@ class DbDjango(DbWriteBase, DbReadBase, UpdateCallback, Callback):
|
|||||||
items[0].delete()
|
items[0].delete()
|
||||||
self.dji.add_repository(repository.serialize())
|
self.dji.add_repository(repository.serialize())
|
||||||
self.dji.add_repository_detail(repository.serialize())
|
self.dji.add_repository_detail(repository.serialize())
|
||||||
|
if not trans.batch:
|
||||||
if items.count() > 0:
|
if items.count() > 0:
|
||||||
self.emit("repository-update", ([repository.handle],))
|
self.emit("repository-update", ([repository.handle],))
|
||||||
else:
|
else:
|
||||||
@ -1569,6 +1581,7 @@ class DbDjango(DbWriteBase, DbReadBase, UpdateCallback, Callback):
|
|||||||
items[0].delete()
|
items[0].delete()
|
||||||
self.dji.add_note(note.serialize())
|
self.dji.add_note(note.serialize())
|
||||||
self.dji.add_note_detail(note.serialize())
|
self.dji.add_note_detail(note.serialize())
|
||||||
|
if not trans.batch:
|
||||||
if items.count() > 0:
|
if items.count() > 0:
|
||||||
self.emit("note-update", ([note.handle],))
|
self.emit("note-update", ([note.handle],))
|
||||||
else:
|
else:
|
||||||
@ -1584,6 +1597,7 @@ class DbDjango(DbWriteBase, DbReadBase, UpdateCallback, Callback):
|
|||||||
items[0].delete()
|
items[0].delete()
|
||||||
self.dji.add_place(place.serialize())
|
self.dji.add_place(place.serialize())
|
||||||
self.dji.add_place_detail(place.serialize())
|
self.dji.add_place_detail(place.serialize())
|
||||||
|
if not trans.batch:
|
||||||
if items.count() > 0:
|
if items.count() > 0:
|
||||||
self.emit("place-update", ([place.handle],))
|
self.emit("place-update", ([place.handle],))
|
||||||
else:
|
else:
|
||||||
@ -1599,6 +1613,7 @@ class DbDjango(DbWriteBase, DbReadBase, UpdateCallback, Callback):
|
|||||||
items[0].delete()
|
items[0].delete()
|
||||||
self.dji.add_event(event.serialize())
|
self.dji.add_event(event.serialize())
|
||||||
self.dji.add_event_detail(event.serialize())
|
self.dji.add_event_detail(event.serialize())
|
||||||
|
if not trans.batch:
|
||||||
if items.count() > 0:
|
if items.count() > 0:
|
||||||
self.emit("event-update", ([event.handle],))
|
self.emit("event-update", ([event.handle],))
|
||||||
else:
|
else:
|
||||||
@ -1614,6 +1629,7 @@ class DbDjango(DbWriteBase, DbReadBase, UpdateCallback, Callback):
|
|||||||
items[0].delete()
|
items[0].delete()
|
||||||
self.dji.add_tag(tag.serialize())
|
self.dji.add_tag(tag.serialize())
|
||||||
self.dji.add_tag_detail(tag.serialize())
|
self.dji.add_tag_detail(tag.serialize())
|
||||||
|
if not trans.batch:
|
||||||
if items.count() > 0:
|
if items.count() > 0:
|
||||||
self.emit("tag-update", ([tag.handle],))
|
self.emit("tag-update", ([tag.handle],))
|
||||||
else:
|
else:
|
||||||
@ -1633,6 +1649,7 @@ class DbDjango(DbWriteBase, DbReadBase, UpdateCallback, Callback):
|
|||||||
items[0].delete()
|
items[0].delete()
|
||||||
self.dji.add_media(media.serialize())
|
self.dji.add_media(media.serialize())
|
||||||
self.dji.add_media_detail(media.serialize())
|
self.dji.add_media_detail(media.serialize())
|
||||||
|
if not trans.batch:
|
||||||
if items.count() > 0:
|
if items.count() > 0:
|
||||||
self.emit("media-update", ([media.handle],))
|
self.emit("media-update", ([media.handle],))
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user