mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00
do GC on autosave
- ensures we're not called as part of the db progress callback - minimises the chance of data loss if a gc causes a crash
This commit is contained in:
parent
82352800a8
commit
a05ebdbefb
2 changed files with 9 additions and 9 deletions
|
@ -134,9 +134,10 @@ crt=?, mod=?, scm=?, dty=?, usn=?, ls=?, conf=?""",
|
|||
self._lastSave = time.time()
|
||||
|
||||
def autosave(self):
|
||||
"Save if 5 minutes has passed since last save."
|
||||
"Save if 5 minutes has passed since last save. True if saved."
|
||||
if time.time() - self._lastSave > 300:
|
||||
self.save()
|
||||
return True
|
||||
|
||||
def lock(self):
|
||||
# make sure we don't accidentally bump mod time
|
||||
|
|
15
aqt/main.py
15
aqt/main.py
|
@ -69,7 +69,7 @@ class AnkiQt(QMainWindow):
|
|||
def setupUI(self):
|
||||
self.col = None
|
||||
self.setupCrashLog()
|
||||
self.setupGC()
|
||||
self.disableGC()
|
||||
self.setupAppMsg()
|
||||
self.setupKeys()
|
||||
self.setupThreads()
|
||||
|
@ -709,8 +709,10 @@ title="%s" %s>%s</button>''' % (
|
|||
self.maybeEnableUndo()
|
||||
|
||||
def autosave(self):
|
||||
self.col.autosave()
|
||||
saved = self.col.autosave()
|
||||
self.maybeEnableUndo()
|
||||
if saved:
|
||||
self.doGC()
|
||||
|
||||
# Other menu operations
|
||||
##########################################################################
|
||||
|
@ -1172,15 +1174,12 @@ Please ensure a profile is open and Anki is not busy, then try again."""),
|
|||
def gcWindow(self, obj):
|
||||
obj.deleteLater()
|
||||
|
||||
def setupGC(self):
|
||||
def disableGC(self):
|
||||
gc.collect()
|
||||
gc.disable()
|
||||
#gc.set_debug(gc.DEBUG_SAVEALL)
|
||||
self.gcTimer = QTimer(self)
|
||||
self.gcTimer.timeout.connect(self.runGC)
|
||||
self.gcTimer.start(60*1000)
|
||||
|
||||
def runGC(self):
|
||||
def doGC(self):
|
||||
assert not self.progress.inDB
|
||||
gc.collect()
|
||||
|
||||
# Crash log
|
||||
|
|
Loading…
Reference in a new issue