Smoother progress for Rebuid reference maps/secondary indices
This commit is contained in:
parent
aeed7edd46
commit
690e8b308e
@ -2509,8 +2509,8 @@ class DbGeneric(DbWriteBase, DbReadBase, UpdateCallback, Callback):
|
|||||||
if version < 20:
|
if version < 20:
|
||||||
gramps_upgrade_20(self)
|
gramps_upgrade_20(self)
|
||||||
|
|
||||||
self.rebuild_secondary()
|
self.rebuild_secondary(callback)
|
||||||
self.reindex_reference_map(self.update)
|
self.reindex_reference_map(callback)
|
||||||
self.reset()
|
self.reset()
|
||||||
|
|
||||||
self.set_schema_version(self.VERSION[0])
|
self.set_schema_version(self.VERSION[0])
|
||||||
|
@ -41,6 +41,7 @@ from gramps.gen.db.dbconst import (DBLOGNAME, DBBACKEND, KEY_TO_NAME_MAP,
|
|||||||
TAG_KEY, CITATION_KEY, REPOSITORY_KEY,
|
TAG_KEY, CITATION_KEY, REPOSITORY_KEY,
|
||||||
REFERENCE_KEY)
|
REFERENCE_KEY)
|
||||||
from gramps.gen.db.generic import DbGeneric
|
from gramps.gen.db.generic import DbGeneric
|
||||||
|
from gramps.gen.updatecallback import UpdateCallback
|
||||||
from gramps.gen.lib import (Tag, Media, Person, Family, Source,
|
from gramps.gen.lib import (Tag, Media, Person, Family, Source,
|
||||||
Citation, Event, Place, Repository, Note)
|
Citation, Event, Place, Repository, Note)
|
||||||
from gramps.gen.lib.genderstats import GenderStats
|
from gramps.gen.lib.genderstats import GenderStats
|
||||||
@ -809,9 +810,14 @@ class DBAPI(DbGeneric):
|
|||||||
"""
|
"""
|
||||||
Reindex all primary records in the database.
|
Reindex all primary records in the database.
|
||||||
"""
|
"""
|
||||||
callback(4)
|
|
||||||
self._txn_begin()
|
self._txn_begin()
|
||||||
self.dbapi.execute("DELETE FROM reference")
|
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 = (
|
primary_table = (
|
||||||
(self.get_person_cursor, Person),
|
(self.get_person_cursor, Person),
|
||||||
(self.get_family_cursor, Family),
|
(self.get_family_cursor, Family),
|
||||||
@ -842,8 +848,8 @@ class DBAPI(DbGeneric):
|
|||||||
obj.__class__.__name__,
|
obj.__class__.__name__,
|
||||||
ref_handle,
|
ref_handle,
|
||||||
ref_class_name])
|
ref_class_name])
|
||||||
|
self.update()
|
||||||
self._txn_commit()
|
self._txn_commit()
|
||||||
callback(5)
|
|
||||||
|
|
||||||
def rebuild_secondary(self, callback=None):
|
def rebuild_secondary(self, callback=None):
|
||||||
"""
|
"""
|
||||||
@ -852,26 +858,26 @@ class DBAPI(DbGeneric):
|
|||||||
if self.readonly:
|
if self.readonly:
|
||||||
return
|
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:
|
# First, expand blob to individual fields:
|
||||||
self._txn_begin()
|
self._txn_begin()
|
||||||
index = 1
|
|
||||||
for obj_type in ('Person', 'Family', 'Event', 'Place', 'Repository',
|
for obj_type in ('Person', 'Family', 'Event', 'Place', 'Repository',
|
||||||
'Source', 'Citation', 'Media', 'Note', 'Tag'):
|
'Source', 'Citation', 'Media', 'Note', 'Tag'):
|
||||||
for handle in self.method('get_%s_handles', obj_type)():
|
for handle in self.method('get_%s_handles', obj_type)():
|
||||||
obj = self.method('get_%s_from_handle', obj_type)(handle)
|
obj = self.method('get_%s_from_handle', obj_type)(handle)
|
||||||
self._update_secondary_values(obj)
|
self._update_secondary_values(obj)
|
||||||
if callback:
|
self.update()
|
||||||
callback(index)
|
|
||||||
index += 1
|
|
||||||
self._txn_commit()
|
self._txn_commit()
|
||||||
if callback:
|
|
||||||
callback(11)
|
|
||||||
|
|
||||||
# Next, rebuild stats:
|
# Next, rebuild stats:
|
||||||
gstats = self.get_gender_stats()
|
gstats = self.get_gender_stats()
|
||||||
self.genderStats = GenderStats(gstats)
|
self.genderStats = GenderStats(gstats)
|
||||||
if callback:
|
|
||||||
callback(12)
|
|
||||||
|
|
||||||
def _has_handle(self, obj_key, handle):
|
def _has_handle(self, obj_key, handle):
|
||||||
table = KEY_TO_NAME_MAP[obj_key]
|
table = KEY_TO_NAME_MAP[obj_key]
|
||||||
|
@ -51,14 +51,13 @@ log = logging.getLogger(".Rebuild")
|
|||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
from gramps.gui.plug import tool
|
from gramps.gui.plug import tool
|
||||||
from gramps.gui.dialog import OkDialog
|
from gramps.gui.dialog import OkDialog
|
||||||
from gramps.gen.updatecallback import UpdateCallback
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# runTool
|
# runTool
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
class Rebuild(tool.Tool, UpdateCallback):
|
class Rebuild(tool.Tool):
|
||||||
|
|
||||||
def __init__(self, dbstate, user, options_class, name, callback=None):
|
def __init__(self, dbstate, user, options_class, name, callback=None):
|
||||||
uistate = user.uistate
|
uistate = user.uistate
|
||||||
@ -76,10 +75,7 @@ class Rebuild(tool.Tool, UpdateCallback):
|
|||||||
uistate.progress.show()
|
uistate.progress.show()
|
||||||
uistate.push_message(dbstate, _("Rebuilding secondary indexes..."))
|
uistate.push_message(dbstate, _("Rebuilding secondary indexes..."))
|
||||||
|
|
||||||
UpdateCallback.__init__(self, self.callback)
|
self.db.rebuild_secondary(self.callback)
|
||||||
self.set_total(12)
|
|
||||||
self.db.rebuild_secondary(self.update)
|
|
||||||
self.reset()
|
|
||||||
|
|
||||||
uistate.set_busy_cursor(False)
|
uistate.set_busy_cursor(False)
|
||||||
uistate.progress.hide()
|
uistate.progress.hide()
|
||||||
@ -88,7 +84,7 @@ class Rebuild(tool.Tool, UpdateCallback):
|
|||||||
parent=uistate.window)
|
parent=uistate.window)
|
||||||
else:
|
else:
|
||||||
print("Rebuilding Secondary Indexes...")
|
print("Rebuilding Secondary Indexes...")
|
||||||
self.db.rebuild_secondary(self.update_empty)
|
self.db.rebuild_secondary(None)
|
||||||
print("All secondary indexes have been rebuilt.")
|
print("All secondary indexes have been rebuilt.")
|
||||||
|
|
||||||
self.db.enable_signals()
|
self.db.enable_signals()
|
||||||
|
@ -53,14 +53,13 @@ log = logging.getLogger(".RebuildRefMap")
|
|||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
from gramps.gui.plug import tool
|
from gramps.gui.plug import tool
|
||||||
from gramps.gui.dialog import OkDialog
|
from gramps.gui.dialog import OkDialog
|
||||||
from gramps.gen.updatecallback import UpdateCallback
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# runTool
|
# runTool
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
class RebuildRefMap(tool.Tool, UpdateCallback):
|
class RebuildRefMap(tool.Tool):
|
||||||
|
|
||||||
def __init__(self, dbstate, user, options_class, name, callback=None):
|
def __init__(self, dbstate, user, options_class, name, callback=None):
|
||||||
uistate = user.uistate
|
uistate = user.uistate
|
||||||
@ -80,10 +79,7 @@ class RebuildRefMap(tool.Tool, UpdateCallback):
|
|||||||
self.callback = None
|
self.callback = None
|
||||||
print(_("Rebuilding reference maps..."))
|
print(_("Rebuilding reference maps..."))
|
||||||
|
|
||||||
UpdateCallback.__init__(self, self.callback)
|
self.db.reindex_reference_map(self.callback)
|
||||||
self.set_total(6)
|
|
||||||
self.db.reindex_reference_map(self.update)
|
|
||||||
self.reset()
|
|
||||||
|
|
||||||
if uistate:
|
if uistate:
|
||||||
uistate.set_busy_cursor(False)
|
uistate.set_busy_cursor(False)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user