From 690e8b308e92324218812093b745b6b97c43eeed Mon Sep 17 00:00:00 2001 From: prculley Date: Fri, 31 Jan 2020 13:53:56 -0600 Subject: [PATCH] Smoother progress for Rebuid reference maps/secondary indices --- gramps/gen/db/generic.py | 4 ++-- gramps/plugins/db/dbapi/dbapi.py | 26 ++++++++++++++++---------- gramps/plugins/tool/rebuild.py | 10 +++------- gramps/plugins/tool/rebuildrefmap.py | 8 ++------ 4 files changed, 23 insertions(+), 25 deletions(-) diff --git a/gramps/gen/db/generic.py b/gramps/gen/db/generic.py index da6b0e97a..4afa34b3b 100644 --- a/gramps/gen/db/generic.py +++ b/gramps/gen/db/generic.py @@ -2509,8 +2509,8 @@ class DbGeneric(DbWriteBase, DbReadBase, UpdateCallback, Callback): if version < 20: gramps_upgrade_20(self) - self.rebuild_secondary() - self.reindex_reference_map(self.update) + self.rebuild_secondary(callback) + self.reindex_reference_map(callback) self.reset() self.set_schema_version(self.VERSION[0]) diff --git a/gramps/plugins/db/dbapi/dbapi.py b/gramps/plugins/db/dbapi/dbapi.py index f20e383e4..f7a75ce49 100644 --- a/gramps/plugins/db/dbapi/dbapi.py +++ b/gramps/plugins/db/dbapi/dbapi.py @@ -41,6 +41,7 @@ from gramps.gen.db.dbconst import (DBLOGNAME, DBBACKEND, KEY_TO_NAME_MAP, TAG_KEY, CITATION_KEY, REPOSITORY_KEY, REFERENCE_KEY) from gramps.gen.db.generic import DbGeneric +from gramps.gen.updatecallback import UpdateCallback from gramps.gen.lib import (Tag, Media, Person, Family, Source, Citation, Event, Place, Repository, Note) from gramps.gen.lib.genderstats import GenderStats @@ -809,9 +810,14 @@ class DBAPI(DbGeneric): """ Reindex all primary records in the database. """ - callback(4) self._txn_begin() self.dbapi.execute("DELETE FROM reference") + total = 0 + for tbl in ('people', 'families', 'events', 'places', 'sources', + 'citations', 'media', 'repositories', 'notes', 'tags'): + total += self.method("get_number_of_%s", tbl)() + UpdateCallback.__init__(self, callback) + self.set_total(total) primary_table = ( (self.get_person_cursor, Person), (self.get_family_cursor, Family), @@ -842,8 +848,8 @@ class DBAPI(DbGeneric): obj.__class__.__name__, ref_handle, ref_class_name]) + self.update() self._txn_commit() - callback(5) def rebuild_secondary(self, callback=None): """ @@ -852,26 +858,26 @@ class DBAPI(DbGeneric): if self.readonly: return + total = 0 + for tbl in ('people', 'families', 'events', 'places', 'sources', + 'citations', 'media', 'repositories', 'notes', 'tags'): + total += self.method("get_number_of_%s", tbl)() + UpdateCallback.__init__(self, callback) + self.set_total(total) + # First, expand blob to individual fields: self._txn_begin() - index = 1 for obj_type in ('Person', 'Family', 'Event', 'Place', 'Repository', 'Source', 'Citation', 'Media', 'Note', 'Tag'): for handle in self.method('get_%s_handles', obj_type)(): obj = self.method('get_%s_from_handle', obj_type)(handle) self._update_secondary_values(obj) - if callback: - callback(index) - index += 1 + self.update() self._txn_commit() - if callback: - callback(11) # Next, rebuild stats: gstats = self.get_gender_stats() self.genderStats = GenderStats(gstats) - if callback: - callback(12) def _has_handle(self, obj_key, handle): table = KEY_TO_NAME_MAP[obj_key] diff --git a/gramps/plugins/tool/rebuild.py b/gramps/plugins/tool/rebuild.py index 11ed7cbd4..1cf1f2619 100644 --- a/gramps/plugins/tool/rebuild.py +++ b/gramps/plugins/tool/rebuild.py @@ -51,14 +51,13 @@ log = logging.getLogger(".Rebuild") #------------------------------------------------------------------------- from gramps.gui.plug import tool from gramps.gui.dialog import OkDialog -from gramps.gen.updatecallback import UpdateCallback #------------------------------------------------------------------------- # # runTool # #------------------------------------------------------------------------- -class Rebuild(tool.Tool, UpdateCallback): +class Rebuild(tool.Tool): def __init__(self, dbstate, user, options_class, name, callback=None): uistate = user.uistate @@ -76,10 +75,7 @@ class Rebuild(tool.Tool, UpdateCallback): uistate.progress.show() uistate.push_message(dbstate, _("Rebuilding secondary indexes...")) - UpdateCallback.__init__(self, self.callback) - self.set_total(12) - self.db.rebuild_secondary(self.update) - self.reset() + self.db.rebuild_secondary(self.callback) uistate.set_busy_cursor(False) uistate.progress.hide() @@ -88,7 +84,7 @@ class Rebuild(tool.Tool, UpdateCallback): parent=uistate.window) else: print("Rebuilding Secondary Indexes...") - self.db.rebuild_secondary(self.update_empty) + self.db.rebuild_secondary(None) print("All secondary indexes have been rebuilt.") self.db.enable_signals() diff --git a/gramps/plugins/tool/rebuildrefmap.py b/gramps/plugins/tool/rebuildrefmap.py index f62c13d9f..eeb89c306 100644 --- a/gramps/plugins/tool/rebuildrefmap.py +++ b/gramps/plugins/tool/rebuildrefmap.py @@ -53,14 +53,13 @@ log = logging.getLogger(".RebuildRefMap") #------------------------------------------------------------------------- from gramps.gui.plug import tool from gramps.gui.dialog import OkDialog -from gramps.gen.updatecallback import UpdateCallback #------------------------------------------------------------------------- # # runTool # #------------------------------------------------------------------------- -class RebuildRefMap(tool.Tool, UpdateCallback): +class RebuildRefMap(tool.Tool): def __init__(self, dbstate, user, options_class, name, callback=None): uistate = user.uistate @@ -80,10 +79,7 @@ class RebuildRefMap(tool.Tool, UpdateCallback): self.callback = None print(_("Rebuilding reference maps...")) - UpdateCallback.__init__(self, self.callback) - self.set_total(6) - self.db.reindex_reference_map(self.update) - self.reset() + self.db.reindex_reference_map(self.callback) if uistate: uistate.set_busy_cursor(False)