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 import Collection
|
||||||
from anki.sound import playFromText, clearAudioQueue, stripSounds
|
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
|
from anki.hooks import runHook, addHook, remHook
|
||||||
import anki.consts
|
import anki.consts
|
||||||
|
|
||||||
|
@ -218,6 +218,7 @@ Are you sure?"""):
|
||||||
def unloadCollection(self):
|
def unloadCollection(self):
|
||||||
if self.col:
|
if self.col:
|
||||||
self.closeAllCollectionWindows()
|
self.closeAllCollectionWindows()
|
||||||
|
self.maybeOptimize()
|
||||||
self.col.close()
|
self.col.close()
|
||||||
self.col = None
|
self.col = None
|
||||||
self.backup()
|
self.backup()
|
||||||
|
@ -255,6 +256,16 @@ Are you sure?"""):
|
||||||
for file in delete:
|
for file in delete:
|
||||||
os.unlink(os.path.join(dir, file[1]))
|
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
|
# State machine
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,7 @@ profileConf = dict(
|
||||||
mainWindowGeom=None,
|
mainWindowGeom=None,
|
||||||
mainWindowState=None,
|
mainWindowState=None,
|
||||||
numBackups=30,
|
numBackups=30,
|
||||||
|
lastOptimize=intTime(),
|
||||||
lang="en",
|
lang="en",
|
||||||
|
|
||||||
# editing
|
# editing
|
||||||
|
@ -54,9 +55,10 @@ profileConf = dict(
|
||||||
syncMedia=True,
|
syncMedia=True,
|
||||||
autoSync=True,
|
autoSync=True,
|
||||||
proxyHost='',
|
proxyHost='',
|
||||||
proxyPass='',
|
|
||||||
proxyPort=8080,
|
proxyPort=8080,
|
||||||
proxyUser='',
|
proxyUser='',
|
||||||
|
proxyPass='',
|
||||||
|
proxyType=3,
|
||||||
)
|
)
|
||||||
|
|
||||||
class ProfileManager(object):
|
class ProfileManager(object):
|
||||||
|
|
|
@ -233,7 +233,7 @@
|
||||||
<normaloff>:/icons/sqlitebrowser.png</normaloff>:/icons/sqlitebrowser.png</iconset>
|
<normaloff>:/icons/sqlitebrowser.png</normaloff>:/icons/sqlitebrowser.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>&Optimize...</string>
|
<string>&Check DB...</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionDocumentation">
|
<action name="actionDocumentation">
|
||||||
|
@ -254,7 +254,7 @@
|
||||||
<normaloff>:/icons/user-identity.png</normaloff>:/icons/user-identity.png</iconset>
|
<normaloff>:/icons/user-identity.png</normaloff>:/icons/user-identity.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>&Profile...</string>
|
<string>&Switch Profile...</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
|
|
Loading…
Reference in a new issue