Skip to content

Commit

Permalink
Speed up refresh() in DictManager
Browse files Browse the repository at this point in the history
This requires adding a (non-unique) index into the dictionary table
  • Loading branch information
1over137 committed Mar 2, 2024
1 parent f6eeb86 commit 9c0fcd5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions vocabsieve/dictmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from .dictionary import getDictsForLang, getFreqlistsForLang, getAudioDictsForLang
from .dictformats import supported_dict_formats, dictinfo
import json
from .tools import profile
from .local_dictionary import LocalDictionary


Expand Down Expand Up @@ -121,6 +122,7 @@ def onRemove(self):
self.refresh()
self.showStats()

@profile
def refresh(self):
dicts = json.loads(self.settings.value("custom_dicts", '[]'))
self.tview.clear()
Expand Down
5 changes: 4 additions & 1 deletion vocabsieve/local_dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ def makeIndex(self) -> None:
try:
self.c.execute("""
CREATE UNIQUE INDEX IF NOT EXISTS dictionary_index ON dictionary(language, dictname, word)
""")
""") # Faster lookups
self.c.execute("""
CREATE INDEX IF NOT EXISTS dictname_index ON dictionary(dictname)
""") # Faster counting of entries
print("Either successfully made unique index, or there is already one")
except sqlite3.IntegrityError:
print("Unable to make unique index")
Expand Down

0 comments on commit 9c0fcd5

Please sign in to comment.