Philipp Hörist pushed to branch master at gajim / gajim
Commits: 17076ced by Philipp Hörist at 2022-12-11T14:13:55+01:00 new: Settings: Allow to create Settings in memory
- - - - - 1d2fa904 by Philipp Hörist at 2022-12-11T14:13:55+01:00 new: Settings: Add shutdown() method
- - - - -
2 changed files:
- gajim/common/application.py - gajim/common/settings.py
Changes:
===================================== gajim/common/application.py ===================================== @@ -244,6 +244,7 @@ def _shutdown_core(self) -> None: app.storage.archive.cleanup_chat_history() app.storage.cache.shutdown() app.storage.archive.shutdown() + app.settings.shutdown() self.end_profiling() logind.shutdown()
===================================== gajim/common/settings.py ===================================== @@ -129,9 +129,10 @@ class SettingsDictT(TypedDict):
class Settings: - def __init__(self): + def __init__(self, in_memory: bool = False): self._con = cast(sqlite3.Connection, None) self._commit_scheduled = None + self._in_memory = in_memory
self._settings: SettingsDictT = {} self._app_overrides: dict[str, AllSettingsT] = {} @@ -220,7 +221,10 @@ def _notify(self,
def init(self) -> None: self._setup_installation_defaults() - self._connect_database() + if self._in_memory: + self._connect_in_memory_database() + else: + self._connect_database() self._load_settings() self._load_account_settings() if not self._settings['app']: @@ -268,6 +272,20 @@ def _connect_database(self) -> None: self._con = sqlite3.connect(path) self._con.row_factory = self._namedtuple_factory
+ def _connect_in_memory_database(self) -> None: + log.info('Creating in memory') + self._con = sqlite3.connect(':memory:') + self._con.row_factory = self._namedtuple_factory + + try: + self._con.executescript(CREATE_SQL) + except Exception: + log.exception('Error') + self._con.close() + sys.exit() + + self._con.commit() + @staticmethod def _create_database(statement: str, path: Path) -> None: log.info('Creating %s', path) @@ -313,6 +331,9 @@ def _scheduled_commit(self) -> None: self._con.commit()
def _migrate_database(self) -> None: + if self._in_memory: + return + try: self._migrate() except Exception: @@ -366,6 +387,9 @@ def _migrate(self) -> None: self._set_user_version(4)
def _migrate_old_config(self) -> None: + if self._in_memory: + return + config_file = configpaths.get('CONFIG_FILE') if not config_file.exists(): return @@ -1319,6 +1343,15 @@ def remove_workspace(self, id_: str) -> None: del self._settings['workspaces'][id_] self._commit_settings('workspaces')
+ def shutdown(self) -> None: + if self._commit_scheduled is not None: + GLib.source_remove(self._commit_scheduled) + self._commit_scheduled = None + + self._commit() + self._con.close() + del self._con +
class LegacyConfig:
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/compare/40243c8e729db9745a1a57cfaff3ca83...