Skip to content

Commit

Permalink
ui: allow to delete old events of the in-memory db
Browse files Browse the repository at this point in the history
Not deleting events from in-memory db can lead to a high mem usage under
certain scenarios.

Previous attempt to solve this issue wrote events to disk in a temporal
file (when using file::memory:?cache=shared).

Related issues: #844 #857

Closes: #1030
  • Loading branch information
gustavo-iniguez-goya committed Nov 5, 2023
1 parent ad896b4 commit bcbfe3b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 4 additions & 1 deletion ui/opensnitch/database/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class Database:
db = None
__instance = None
DB_IN_MEMORY = ":memory:"
DB_IN_MEMORY = "file::memory:"
DB_TYPE_MEMORY = 0
DB_TYPE_FILE = 1
DB_JRNL_WAL = False
Expand Down Expand Up @@ -50,6 +50,8 @@ def initialize(self, dbtype=DB_TYPE_MEMORY, dbfile=DB_IN_MEMORY, dbjrnl_wal=DB_J

self.db = QSqlDatabase.addDatabase("QSQLITE", self.db_name)
self.db.setDatabaseName(self.db_file)
if dbtype == Database.DB_TYPE_MEMORY:
self.db.setConnectOptions("QSQLITE_OPEN_URI;QSQLITE_ENABLE_SHARED_CACHE")
if not self.db.open():
print("\n ** Error opening DB: SQLite driver not loaded. DB name: %s\n" % self.db_file)
print("\n Available drivers: ", QSqlDatabase.drivers())
Expand Down Expand Up @@ -103,6 +105,7 @@ def get_db_name(self):
return self.db_name

def _create_tables(self):
# https://www.sqlite.org/wal.html
if self.db_file == Database.DB_IN_MEMORY:
self.set_schema_version(self.DB_VERSION)
# Disable journal (default)
Expand Down
5 changes: 3 additions & 2 deletions ui/opensnitch/dialogs/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def __init__(self, parent=None, appicon=None):
self.setupUi(self)
self.setWindowIcon(appicon)

self.checkDBMaxDays.setEnabled(True)
self.dbFileButton.setVisible(False)
self.dbLabel.setVisible(False)
self.dbType = None
Expand Down Expand Up @@ -773,6 +774,7 @@ def _reset_status_message(self):
self._hide_status_label()

def _enable_db_cleaner_options(self, enable, db_max_days):
self.checkDBMaxDays.setChecked(enable)
self.spinDBMaxDays.setEnabled(enable)
self.spinDBPurgeInterval.setEnabled(enable)
self.labelDBPurgeInterval.setEnabled(enable)
Expand Down Expand Up @@ -823,8 +825,7 @@ def _cb_db_type_changed(self):
isDBMem = self.comboDBType.currentIndex() == Database.DB_TYPE_MEMORY
self.dbFileButton.setVisible(not isDBMem)
self.dbLabel.setVisible(not isDBMem)
self.checkDBMaxDays.setEnabled(not isDBMem)
self.checkDBMaxDays.setChecked(not isDBMem)
self.checkDBMaxDays.setChecked(self._cfg.getBool(Config.DEFAULT_DB_PURGE_OLDEST))
self.checkDBJrnlWal.setEnabled(not isDBMem)
self.checkDBJrnlWal.setChecked(False)

Expand Down

0 comments on commit bcbfe3b

Please sign in to comment.