diff options
author | Florian Bruhin <me@the-compiler.org> | 2021-01-02 16:46:16 +0100 |
---|---|---|
committer | Florian Bruhin <me@the-compiler.org> | 2021-01-02 16:46:16 +0100 |
commit | 6c8a833f2763459b54c4ef9bbe6d11d80ce307fa (patch) | |
tree | abe2d8ffa7cf03d39e917e5f5ce85d1ccbe30c16 | |
parent | 47f2093b50af4428617b7fe4a4f1c78154043e8e (diff) | |
parent | 785c59c5f6cb67369c144b69d42e308500b17c9a (diff) | |
download | qutebrowser-6c8a833f2763459b54c4ef9bbe6d11d80ce307fa.tar.gz qutebrowser-6c8a833f2763459b54c4ef9bbe6d11d80ce307fa.zip |
Merge remote-tracking branch 'origin/pr/5871'
-rw-r--r-- | qutebrowser/browser/history.py | 17 | ||||
-rw-r--r-- | tests/unit/browser/test_history.py | 53 |
2 files changed, 35 insertions, 35 deletions
diff --git a/qutebrowser/browser/history.py b/qutebrowser/browser/history.py index 04cc5a088..37bc03181 100644 --- a/qutebrowser/browser/history.py +++ b/qutebrowser/browser/history.py @@ -79,7 +79,7 @@ class CompletionMetaInfo(sql.SqlTable): """Table containing meta-information for the completion.""" KEYS = { - 'force_rebuild': False, + 'excluded_patterns': '', } def __init__(self, parent=None): @@ -158,9 +158,14 @@ class WebHistory(sql.SqlTable): if sql.Query('pragma user_version').run().value() < _USER_VERSION: self.completion.delete_all() - if self.metainfo['force_rebuild']: + + # Get a string of all patterns + patterns = config.instance.get_str('completion.web_history.exclude') + + # If patterns changed, update them in database and rebuild completion + if self.metainfo['excluded_patterns'] != patterns: + self.metainfo['excluded_patterns'] = patterns self.completion.delete_all() - self.metainfo['force_rebuild'] = False if not self.completion: # either the table is out-of-date or the user wiped it manually @@ -183,18 +188,12 @@ class WebHistory(sql.SqlTable): 'ORDER BY atime desc ' 'limit :limit offset :offset') - config.instance.changed.connect(self._on_config_changed) - def __repr__(self): return utils.get_repr(self, length=len(self)) def __contains__(self, url): return self._contains_query.run(val=url).value() - @config.change_filter('completion.web_history.exclude') - def _on_config_changed(self): - self.metainfo['force_rebuild'] = True - @contextlib.contextmanager def _handle_sql_errors(self): try: diff --git a/tests/unit/browser/test_history.py b/tests/unit/browser/test_history.py index c1990de0d..b64741592 100644 --- a/tests/unit/browser/test_history.py +++ b/tests/unit/browser/test_history.py @@ -402,30 +402,12 @@ class TestRebuild: ('example.com/2', '', 2), ] - def test_force_rebuild(self, web_history, stubs): - """Ensure that completion is regenerated if we force a rebuild.""" - web_history.add_url(QUrl('example.com/1'), redirect=False, atime=1) - web_history.add_url(QUrl('example.com/2'), redirect=False, atime=2) - web_history.completion.delete('url', 'example.com/2') - - hist2 = history.WebHistory(progress=stubs.FakeHistoryProgress()) - assert list(hist2.completion) == [('example.com/1', '', 1)] - hist2.metainfo['force_rebuild'] = True - - hist3 = history.WebHistory(progress=stubs.FakeHistoryProgress()) - assert list(hist3.completion) == [ - ('example.com/1', '', 1), - ('example.com/2', '', 2), - ] - assert not hist3.metainfo['force_rebuild'] - def test_exclude(self, config_stub, web_history, stubs): """Ensure that patterns in completion.web_history.exclude are ignored. This setting should only be used for the completion. """ config_stub.val.completion.web_history.exclude = ['*.example.org'] - assert web_history.metainfo['force_rebuild'] web_history.add_url(QUrl('http://example.com'), redirect=False, atime=1) @@ -435,16 +417,35 @@ class TestRebuild: hist2 = history.WebHistory(progress=stubs.FakeHistoryProgress()) assert list(hist2.completion) == [('http://example.com', '', 1)] - def test_unrelated_config_change(self, config_stub, web_history): - config_stub.val.history_gap_interval = 1234 - assert not web_history.metainfo['force_rebuild'] + def test_pattern_change_rebuild(self, config_stub, web_history, stubs): + """Ensure that completion is rebuilt when exclude patterns change.""" + config_stub.val.completion.web_history.exclude = ['*.example.org'] + + web_history.add_url(QUrl('http://example.com'), + redirect=False, atime=1) + web_history.add_url(QUrl('http://example.org'), + redirect=False, atime=2) + + hist2 = history.WebHistory(progress=stubs.FakeHistoryProgress()) + assert list(hist2.completion) == [ + ('http://example.com', '', 1), + ] + + config_stub.val.completion.web_history.exclude = [] + + hist3 = history.WebHistory(progress=stubs.FakeHistoryProgress()) + assert list(hist3.completion) == [ + ('http://example.com', '', 1), + ('http://example.org', '', 2) + ] @pytest.mark.parametrize('patch_threshold', [True, False]) def test_progress(self, web_history, config_stub, monkeypatch, stubs, patch_threshold): web_history.add_url(QUrl('example.com/1'), redirect=False, atime=1) web_history.add_url(QUrl('example.com/2'), redirect=False, atime=2) - web_history.metainfo['force_rebuild'] = True + # Change cached patterns to trigger a completion rebuild + web_history.metainfo['excluded_patterns'] = 'http://example.org' if patch_threshold: monkeypatch.setattr(history.WebHistory, '_PROGRESS_THRESHOLD', 1) @@ -476,12 +477,12 @@ class TestCompletionMetaInfo: metainfo['does_not_exist'] = 42 def test_contains(self, metainfo): - assert 'force_rebuild' in metainfo + assert 'excluded_patterns' in metainfo def test_modify(self, metainfo): - assert not metainfo['force_rebuild'] - metainfo['force_rebuild'] = True - assert metainfo['force_rebuild'] + assert not metainfo['excluded_patterns'] + metainfo['excluded_patterns'] = 'https://example.com/' + assert metainfo['excluded_patterns'] class TestHistoryProgress: |