Reworked backend Cursors; don't emit changes when changing in batch mode

This commit is contained in:
Doug Blank 2015-05-14 09:07:10 -04:00
parent 6da7f78cba
commit 1118ce449c
4 changed files with 121 additions and 2124 deletions

View File

File diff suppressed because it is too large Load Diff

View File

@ -130,27 +130,33 @@ class Cursor(object):
def __init__(self, map, func):
self.map = map
self.func = func
self._iter = self.__iter__()
def __enter__(self):
return self
def __iter__(self):
return self.__next__()
def __next__(self):
for item in self.map.keys():
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):
pass
def iter(self):
for item in self.map.keys():
yield (bytes(item, "utf-8"), self.func(item))
yield None
def first(self):
self._iter = self.__iter__()
return self.next()
try:
return next(self._iter)
except:
return
def next(self):
try:
return next(self._iter)
except:
return None
return
def close(self):
pass
@ -1099,6 +1105,7 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
return obj.handle
def commit_person(self, person, trans, change_time=None):
if not trans.batch:
if person.handle in self.person_map:
self.emit("person-update", ([person.handle],))
else:
@ -1106,6 +1113,7 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
self.person_map[person.handle] = person
def commit_family(self, family, trans, change_time=None):
if not trans.batch:
if family.handle in self.family_map:
self.emit("family-update", ([family.handle],))
else:
@ -1113,6 +1121,7 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
self.family_map[family.handle] = family
def commit_citation(self, citation, trans, change_time=None):
if not trans.batch:
if citation.handle in self.citation_map:
self.emit("citation-update", ([citation.handle],))
else:
@ -1120,6 +1129,7 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
self.citation_map[citation.handle] = citation
def commit_source(self, source, trans, change_time=None):
if not trans.batch:
if source.handle in self.source_map:
self.emit("source-update", ([source.handle],))
else:
@ -1127,6 +1137,7 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
self.source_map[source.handle] = source
def commit_repository(self, repository, trans, change_time=None):
if not trans.batch:
if repository.handle in self.repository_map:
self.emit("repository-update", ([repository.handle],))
else:
@ -1134,6 +1145,7 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
self.repository_map[repository.handle] = repository
def commit_note(self, note, trans, change_time=None):
if not trans.batch:
if note.handle in self.note_map:
self.emit("note-update", ([note.handle],))
else:
@ -1141,6 +1153,7 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
self.note_map[note.handle] = note
def commit_place(self, place, trans, change_time=None):
if not trans.batch:
if place.handle in self.place_map:
self.emit("place-update", ([place.handle],))
else:
@ -1148,6 +1161,7 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
self.place_map[place.handle] = place
def commit_event(self, event, trans, change_time=None):
if not trans.batch:
if event.handle in self.event_map:
self.emit("event-update", ([event.handle],))
else:
@ -1155,6 +1169,7 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
self.event_map[event.handle] = event
def commit_tag(self, tag, trans, change_time=None):
if not trans.batch:
if tag.handle in self.tag_map:
self.emit("tag-update", ([tag.handle],))
else:
@ -1162,6 +1177,7 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
self.tag_map[tag.handle] = tag
def commit_media_object(self, media, transaction, change_time=None):
if not trans.batch:
if media.handle in self.media_map:
self.emit("media-update", ([media.handle],))
else:

View File

@ -127,13 +127,17 @@ class Cursor(object):
def __init__(self, model, func):
self.model = model
self.func = func
self._iter = self.__iter__()
def __enter__(self):
return self
def __iter__(self):
return self.__next__()
def __next__(self):
for item in self.model.all():
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):
pass
def iter(self):
@ -142,7 +146,10 @@ class Cursor(object):
yield None
def first(self):
self._iter = self.__iter__()
return self.next()
try:
return next(self._iter)
except:
return
def next(self):
try:
return next(self._iter)
@ -1494,6 +1501,7 @@ class DbDjango(DbWriteBase, DbReadBase, UpdateCallback, Callback):
items[0].delete()
self.dji.add_person(person.serialize())
self.dji.add_person_detail(person.serialize())
if not trans.batch:
if items.count() > 0:
self.emit("person-update", ([person.handle],))
else:
@ -1509,6 +1517,7 @@ class DbDjango(DbWriteBase, DbReadBase, UpdateCallback, Callback):
items[0].delete()
self.dji.add_family(family.serialize())
self.dji.add_family_detail(family.serialize())
if not trans.batch:
if items.count() > 0:
self.emit("family-update", ([family.handle],))
else:
@ -1524,6 +1533,7 @@ class DbDjango(DbWriteBase, DbReadBase, UpdateCallback, Callback):
items[0].delete()
self.dji.add_citation(citation.serialize())
self.dji.add_citation_detail(citation.serialize())
if not trans.batch:
if items.count() > 0:
self.emit("citation-update", ([citation.handle],))
else:
@ -1539,6 +1549,7 @@ class DbDjango(DbWriteBase, DbReadBase, UpdateCallback, Callback):
items[0].delete()
self.dji.add_source(source.serialize())
self.dji.add_source_detail(source.serialize())
if not trans.batch:
if items.count() > 0:
self.emit("source-update", ([source.handle],))
else:
@ -1554,6 +1565,7 @@ class DbDjango(DbWriteBase, DbReadBase, UpdateCallback, Callback):
items[0].delete()
self.dji.add_repository(repository.serialize())
self.dji.add_repository_detail(repository.serialize())
if not trans.batch:
if items.count() > 0:
self.emit("repository-update", ([repository.handle],))
else:
@ -1569,6 +1581,7 @@ class DbDjango(DbWriteBase, DbReadBase, UpdateCallback, Callback):
items[0].delete()
self.dji.add_note(note.serialize())
self.dji.add_note_detail(note.serialize())
if not trans.batch:
if items.count() > 0:
self.emit("note-update", ([note.handle],))
else:
@ -1584,6 +1597,7 @@ class DbDjango(DbWriteBase, DbReadBase, UpdateCallback, Callback):
items[0].delete()
self.dji.add_place(place.serialize())
self.dji.add_place_detail(place.serialize())
if not trans.batch:
if items.count() > 0:
self.emit("place-update", ([place.handle],))
else:
@ -1599,6 +1613,7 @@ class DbDjango(DbWriteBase, DbReadBase, UpdateCallback, Callback):
items[0].delete()
self.dji.add_event(event.serialize())
self.dji.add_event_detail(event.serialize())
if not trans.batch:
if items.count() > 0:
self.emit("event-update", ([event.handle],))
else:
@ -1614,6 +1629,7 @@ class DbDjango(DbWriteBase, DbReadBase, UpdateCallback, Callback):
items[0].delete()
self.dji.add_tag(tag.serialize())
self.dji.add_tag_detail(tag.serialize())
if not trans.batch:
if items.count() > 0:
self.emit("tag-update", ([tag.handle],))
else:
@ -1633,6 +1649,7 @@ class DbDjango(DbWriteBase, DbReadBase, UpdateCallback, Callback):
items[0].delete()
self.dji.add_media(media.serialize())
self.dji.add_media_detail(media.serialize())
if not trans.batch:
if items.count() > 0:
self.emit("media-update", ([media.handle],))
else: