* autobackup; add delay after wake from sleep/hibernate to allow time
for system to settle.

Fixes #10953

* Autobackup only if new commits since last autobackup in session
This commit is contained in:
Paul Culley 2020-08-21 09:46:18 -05:00 committed by GitHub
parent 261a3d8965
commit 8654c50594
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 40 additions and 4 deletions

View File

@ -537,7 +537,7 @@ class DbGeneric(DbWriteBase, DbReadBase, UpdateCallback, Callback):
self.transaction = None
self.abort_possible = False
self._bm_changes = 0
self.has_changed = False
self.has_changed = 0 # Also gives commits since startup
self.surname_list = []
self.genderStats = GenderStats() # can pass in loaded stats as dict
self.owner = Researcher()

View File

@ -1779,7 +1779,9 @@ class GrampsPreferences(ConfigureDialog):
formats = [_("Never"),
_("Every 15 minutes"),
_("Every 30 minutes"),
_("Every hour")]
_("Every hour"),
_("Every 12 hours"),
_("Every day")]
list(map(obox.append_text, formats))
active = config.get('database.autobackup')
obox.set_active(active)

View File

@ -458,6 +458,10 @@ class DisplayState(Callback):
minutes = 30
elif interval == 3:
minutes = 60
elif interval == 4:
minutes = 720
elif interval == 5:
minutes = 1440
if interval > 0:
self.backup_timer = GLib.timeout_add_seconds(
minutes*60, self.__emit_autobackup)

View File

@ -56,6 +56,7 @@ LOG = logging.getLogger(".")
#-------------------------------------------------------------------------
from gi.repository import Gtk
from gi.repository import Gdk
from gi.repository import GLib
#-------------------------------------------------------------------------
#
@ -181,6 +182,9 @@ class ViewManager(CLIManager):
self.views = None
self.current_views = [] # The current view in each category
self.view_changing = False
self.autobackup_time = time.time() # time of start or last autobackup
self.delay_timer = None # autobackup delay timer for after wakeup
self.prev_has_changed = 0 # db commit count at autobackup time
self.show_navigator = config.get('interface.view')
self.show_toolbar = config.get('interface.toolbar-on')
@ -1183,7 +1187,33 @@ class ViewManager(CLIManager):
"""
Backup the current family tree.
"""
if self.dbstate.db.is_open() and self.dbstate.db.has_changed:
if self.delay_timer is not None:
GLib.source_remove(self.delay_timer)
self.delay_timer = None
interval = config.get('database.autobackup')
if interval == 1:
seconds = 900. # 15min *60
elif interval == 2:
seconds = 1800. # 30min *60
elif interval == 3:
seconds = 3600. # 60min *60
elif interval == 4:
seconds = 43200. # (12 hours) 720min *60
elif interval == 5:
seconds = 86400. # (24 hours) 1440min *60
now = time.time()
if interval and now > self.autobackup_time + seconds + 300.:
# we have been delayed by more than 5 minutes
# so we have probably been awakened from sleep/hibernate
# we should delay a bit more to let the system settle
self.delay_timer = GLib.timeout_add_seconds(300, self.autobackup)
self.autobackup_time = now
return
self.autobackup_time = now
# Only backup if more commits since last time
if(self.dbstate.db.is_open() and
self.dbstate.db.has_changed > self.prev_has_changed):
self.prev_has_changed = self.dbstate.db.has_changed
self.uistate.set_busy_cursor(True)
self.uistate.progress.show()
self.uistate.push_message(self.dbstate, _("Autobackup..."))

View File

@ -276,7 +276,7 @@ class DBAPI(DbGeneric):
self.undodb.commit(txn, msg)
self._after_commit(txn)
txn.clear()
self.has_changed = True
self.has_changed += 1 # Also gives commits since startup
def transaction_abort(self, txn):
"""