Fix history completion delete function.

In order to update SqlQueryModel's rowCount after re-running the query,
we must call setQuery again.
This commit is contained in:
Ryan Roden-Corrent 2017-06-27 08:40:43 -04:00
parent 62a849c2db
commit f06880c6e2
3 changed files with 9 additions and 4 deletions

View File

@ -99,5 +99,6 @@ class SqlCategory(QSqlQueryModel):
for i in range(self.columnCount())]
self.delete_func(data)
# re-run query to reload updated table
with debug.log_time('sql', 'Running completion query'):
with debug.log_time('sql', 'Re-running completion query post-delete'):
self._query.run()
self.setQuery(self._query)

View File

@ -532,6 +532,10 @@ class WebHistoryStub(sql.SqlTable):
self.completion = sql.SqlTable("CompletionHistory",
['url', 'title', 'last_atime'])
def __contains__(self, url):
q = self.contains_query('url')
return q.run(val=url).value()
def add_url(self, url, title="", *, redirect=False, atime=None):
self.insert({'url': url, 'title': title, 'atime': atime,
'redirect': redirect})
@ -540,7 +544,6 @@ class WebHistoryStub(sql.SqlTable):
'title': title,
'last_atime': atime})
def delete_url(self, url):
"""Remove all history entries with the given url.

View File

@ -392,8 +392,9 @@ def test_url_completion_delete_history(qtmodeltester, config_stub,
assert model.data(parent) == "History"
assert model.data(idx) == 'https://python.org'
assert 'https://python.org' in web_history_stub
model.delete_cur_item(idx)
assert not web_history_stub.contains('url', 'https://python.org')
assert 'https://python.org' not in web_history_stub
def test_session_completion(qtmodeltester, session_manager_stub):
@ -594,7 +595,7 @@ def test_url_completion_benchmark(benchmark, config_stub,
'title': ['title{}'.format(i) for i in r]
}
web_history_stub.completions.insert_batch(entries)
web_history_stub.completion.insert_batch(entries)
quickmark_manager_stub.marks = collections.OrderedDict([
('title{}'.format(i), 'example.com/{}'.format(i))