Smoother progress for Rebuid reference maps/secondary indices

This commit is contained in:
prculley 2020-01-31 13:53:56 -06:00 committed by Paul Culley
parent aeed7edd46
commit 690e8b308e
4 changed files with 23 additions and 25 deletions

View File

@ -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])

View File

@ -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]

View File

@ -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()

View File

@ -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)