mirror of
https://github.com/ankitects/anki.git
synced 2025-09-23 16:26:40 -04:00
add auto optimiziation on close
This commit is contained in:
parent
fb88fe2e45
commit
b025eb9983
3 changed files with 17 additions and 4 deletions
13
aqt/main.py
13
aqt/main.py
|
@ -11,7 +11,7 @@ QtConfig = pyqtconfig.Configuration()
|
|||
|
||||
from anki import Collection
|
||||
from anki.sound import playFromText, clearAudioQueue, stripSounds
|
||||
from anki.utils import stripHTML, checksum, isWin, isMac
|
||||
from anki.utils import stripHTML, checksum, isWin, isMac, intTime
|
||||
from anki.hooks import runHook, addHook, remHook
|
||||
import anki.consts
|
||||
|
||||
|
@ -218,6 +218,7 @@ Are you sure?"""):
|
|||
def unloadCollection(self):
|
||||
if self.col:
|
||||
self.closeAllCollectionWindows()
|
||||
self.maybeOptimize()
|
||||
self.col.close()
|
||||
self.col = None
|
||||
self.backup()
|
||||
|
@ -255,6 +256,16 @@ Are you sure?"""):
|
|||
for file in delete:
|
||||
os.unlink(os.path.join(dir, file[1]))
|
||||
|
||||
def maybeOptimize(self):
|
||||
# has two weeks passed?
|
||||
if (intTime() - self.pm.profile['lastOptimize']) < 86400*14:
|
||||
return
|
||||
self.progress.start(label=_("Optimizing..."), immediate=True)
|
||||
self.col.optimize()
|
||||
self.pm.profile['lastOptimize'] = intTime()
|
||||
self.pm.save()
|
||||
self.progress.finish()
|
||||
|
||||
# State machine
|
||||
##########################################################################
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ profileConf = dict(
|
|||
mainWindowGeom=None,
|
||||
mainWindowState=None,
|
||||
numBackups=30,
|
||||
lastOptimize=intTime(),
|
||||
lang="en",
|
||||
|
||||
# editing
|
||||
|
@ -54,9 +55,10 @@ profileConf = dict(
|
|||
syncMedia=True,
|
||||
autoSync=True,
|
||||
proxyHost='',
|
||||
proxyPass='',
|
||||
proxyPort=8080,
|
||||
proxyUser='',
|
||||
proxyPass='',
|
||||
proxyType=3,
|
||||
)
|
||||
|
||||
class ProfileManager(object):
|
||||
|
|
|
@ -233,7 +233,7 @@
|
|||
<normaloff>:/icons/sqlitebrowser.png</normaloff>:/icons/sqlitebrowser.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&Optimize...</string>
|
||||
<string>&Check DB...</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionDocumentation">
|
||||
|
@ -254,7 +254,7 @@
|
|||
<normaloff>:/icons/user-identity.png</normaloff>:/icons/user-identity.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&Profile...</string>
|
||||
<string>&Switch Profile...</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
|
|
Loading…
Reference in a new issue