diff options
author | Florian Bruhin <me@the-compiler.org> | 2021-01-05 18:07:05 +0100 |
---|---|---|
committer | Florian Bruhin <me@the-compiler.org> | 2021-01-05 18:32:57 +0100 |
commit | 4414a349d9f44736eb10724e7fa332f422a95db6 (patch) | |
tree | 16b4569ab96a3a411164a01f7b0b0db15a280a8b | |
parent | fcfa069a06ade76d91bac38127f3235c13d78eb1 (diff) | |
download | qutebrowser-4414a349d9f44736eb10724e7fa332f422a95db6.tar.gz qutebrowser-4414a349d9f44736eb10724e7fa332f422a95db6.zip |
history: Use new user version handling
-rw-r--r-- | qutebrowser/browser/history.py | 42 |
1 files changed, 9 insertions, 33 deletions
diff --git a/qutebrowser/browser/history.py b/qutebrowser/browser/history.py index 3a25284e3..d39519bed 100644 --- a/qutebrowser/browser/history.py +++ b/qutebrowser/browser/history.py @@ -32,14 +32,6 @@ from qutebrowser.api import cmdutils from qutebrowser.utils import utils, log, usertypes, message, qtutils from qutebrowser.misc import objects, sql -# Increment for schema changes, or if HistoryCompletion needs to be regenerated. -# -# Changes from 0 -> 1 and 1 -> 2: -# - None (only needs history regeneration) -# -# Changes from 2 -> 3: -# - History cleanup is run -_USER_VERSION = 3 web_history = cast('WebHistory', None) @@ -169,12 +161,18 @@ class WebHistory(sql.SqlTable): # Store the last saved url to avoid duplicate immediate saves. self._last_url = None - version_changed = self._run_migrations() - self.completion = CompletionHistory(parent=self) self.metainfo = CompletionMetaInfo(parent=self) - if version_changed: + if sql.db_user_version != sql.USER_VERSION: + # If the DB user version changed, run a full cleanup and rebuild the + # completion history. + # + # In the future, this could be improved to only be done when actually needed + # - but version changes happen very infrequently, rebuilding everything + # gives us less corner-cases to deal with, and we can run a VACUUM to make + # things smaller. + self._cleanup_history() self.completion.delete_all() # Get a string of all patterns @@ -219,28 +217,6 @@ class WebHistory(sql.SqlTable): except sql.KnownError as e: message.error(f"Failed to write history: {e.text()}") - def _run_migrations(self): - """Run migrations needed, based on the stored user_version. - - NOTE: This runs before self.completion or self.metainfo are available! - - Return: - True if the version changed, False otherwise. - """ - db_version = sql.Query('pragma user_version').run().value() - assert db_version >= 0, db_version - - if db_version != _USER_VERSION: - sql.Query(f'PRAGMA user_version = {_USER_VERSION}').run() - - if db_version < 3: - self._cleanup_history() - return True - - # FIXME handle too new user_version - assert db_version == _USER_VERSION, db_version - return False - def _is_excluded_from_completion(self, url): """Check if the given URL is excluded from the completion.""" patterns = config.cache['completion.web_history.exclude'] |