Skip to content

Commit

Permalink
use in-memory sqlite db when --sort --no-sqlite is given
Browse files Browse the repository at this point in the history
increases running time a little, but reduces memory usage a lot
  • Loading branch information
ilius committed Dec 7, 2024
1 parent d34de5d commit b03b619
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pyglossary/glossary_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,15 @@ def clear(self) -> None:
self.initVars()
self._data.clear()

def _newInMemorySqEntryList(self) -> SqEntryList:
return SqEntryList(
entryToRaw=self._entryToRaw,
entryFromRaw=self._entryFromRaw,
filename="file::memory:", # or "file::memory:?cache=shared"
create=True,
persist=True,
)

def __init__(
self,
info: dict[str, str] | None = None,
Expand Down Expand Up @@ -1052,6 +1061,8 @@ def _resolveSortParams(
self._switchToSQLite(
inputFilename=args.inputFilename,
)
else:
self._data = self._newInMemorySqEntryList()

self._data.setSortKey(
namedSortKey=namedSortKey,
Expand Down

0 comments on commit b03b619

Please sign in to comment.