Fix long hang after importing history.
Turns out historyContains was getting called for the webkit backend multiple times when the browser starts. This was calling `url in history`, which was enumerating the entire history as `__contains__` was not defined.
This commit is contained in:
parent
024386d189
commit
f110cf4d53
@ -83,6 +83,9 @@ class WebHistory(sql.SqlTable):
|
||||
def __repr__(self):
|
||||
return utils.get_repr(self, length=len(self))
|
||||
|
||||
def __contains__(self, url):
|
||||
return self.contains('url', url)
|
||||
|
||||
def _add_entry(self, entry):
|
||||
"""Add an entry to the in-memory database."""
|
||||
self.insert([entry.url_str(), entry.title, entry.atime,
|
||||
|
@ -139,6 +139,17 @@ class SqlTable(QObject):
|
||||
rec = result.record()
|
||||
yield self.Entry(*[rec.value(i) for i in range(rec.count())])
|
||||
|
||||
def contains(self, field, value):
|
||||
"""Return whether the table contains the matching item.
|
||||
|
||||
Args:
|
||||
field: Field to match.
|
||||
value: Value to check for the given field.
|
||||
"""
|
||||
query = run_query("SELECT * FROM {} where {} = ? LIMIT 1"
|
||||
.format(self._name, field), [value])
|
||||
return query.next()
|
||||
|
||||
def __len__(self):
|
||||
"""Return the count of rows in the table."""
|
||||
result = run_query("SELECT count(*) FROM {}".format(self._name))
|
||||
|
@ -63,6 +63,14 @@ def test_len(hist):
|
||||
assert len(hist) == 1
|
||||
|
||||
|
||||
def test_contains(hist):
|
||||
hist.add_url(QUrl('http://www.example.com/'), title='Title', atime=12345)
|
||||
assert 'http://www.example.com/' in hist
|
||||
assert not 'www.example.com' in hist
|
||||
assert not 'Title' in hist
|
||||
assert not 12345 in hist
|
||||
|
||||
|
||||
def test_get_recent(hist):
|
||||
hist.add_url(QUrl('http://www.qutebrowser.org/'), atime=67890)
|
||||
hist.add_url(QUrl('http://example.com/'), atime=12345)
|
||||
|
@ -88,6 +88,22 @@ def test_len():
|
||||
assert len(table) == 3
|
||||
|
||||
|
||||
def test_contains():
|
||||
table = sql.SqlTable('Foo', ['name', 'val', 'lucky'])
|
||||
table.insert(['one', 1, False])
|
||||
table.insert(['nine', 9, False])
|
||||
table.insert(['thirteen', 13, True])
|
||||
assert table.contains('name', 'one')
|
||||
assert table.contains('name', 'thirteen')
|
||||
assert table.contains('val', 9)
|
||||
assert table.contains('lucky', False)
|
||||
assert table.contains('lucky', True)
|
||||
assert not table.contains('name', 'oone')
|
||||
assert not table.contains('name', 1)
|
||||
assert not table.contains('name', '*')
|
||||
assert not table.contains('val', 10)
|
||||
|
||||
|
||||
def test_delete_all(qtbot):
|
||||
table = sql.SqlTable('Foo', ['name', 'val', 'lucky'])
|
||||
table.insert(['one', 1, False])
|
||||
|
Loading…
Reference in New Issue
Block a user