Merge pull request #2871 from rcorre/fix-fetch-delete
Fix fetch/delete sql category bug.
This commit is contained in:
commit
cee82a3c7b
@ -93,10 +93,12 @@ class HistoryCategory(QSqlQueryModel):
|
|||||||
self._query.run(pat=pattern)
|
self._query.run(pat=pattern)
|
||||||
self.setQuery(self._query)
|
self.setQuery(self._query)
|
||||||
|
|
||||||
def removeRows(self, _row, _count, _parent=None):
|
def removeRows(self, row, _count, _parent=None):
|
||||||
"""Override QAbstractItemModel::removeRows to re-run sql query."""
|
"""Override QAbstractItemModel::removeRows to re-run sql query."""
|
||||||
# re-run query to reload updated table
|
# re-run query to reload updated table
|
||||||
with debug.log_time('sql', 'Re-running completion query post-delete'):
|
with debug.log_time('sql', 'Re-running completion query post-delete'):
|
||||||
self._query.run()
|
self._query.run()
|
||||||
self.setQuery(self._query)
|
self.setQuery(self._query)
|
||||||
|
while self.rowCount() < row:
|
||||||
|
self.fetchMore()
|
||||||
return True
|
return True
|
||||||
|
@ -22,7 +22,6 @@
|
|||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from PyQt5.QtCore import QModelIndex
|
|
||||||
|
|
||||||
from qutebrowser.misc import sql
|
from qutebrowser.misc import sql
|
||||||
from qutebrowser.completion.models import histcategory
|
from qutebrowser.completion.models import histcategory
|
||||||
@ -147,6 +146,22 @@ def test_remove_rows(hist, model_validator):
|
|||||||
model_validator.set_model(cat)
|
model_validator.set_model(cat)
|
||||||
cat.set_pattern('')
|
cat.set_pattern('')
|
||||||
hist.delete('url', 'foo')
|
hist.delete('url', 'foo')
|
||||||
# histcategory does not care which index was removed, it just regenerates
|
cat.removeRows(0, 1)
|
||||||
cat.removeRows(QModelIndex(), 1)
|
|
||||||
model_validator.validate([('bar', 'Bar', '')])
|
model_validator.validate([('bar', 'Bar', '')])
|
||||||
|
|
||||||
|
|
||||||
|
def test_remove_rows_fetch(hist):
|
||||||
|
"""removeRows should fetch enough data to make the current index valid."""
|
||||||
|
# we cannot use model_validator as it will fetch everything up front
|
||||||
|
hist.insert_batch({'url': [str(i) for i in range(300)]})
|
||||||
|
cat = histcategory.HistoryCategory()
|
||||||
|
cat.set_pattern('')
|
||||||
|
|
||||||
|
# sanity check that we didn't fetch everything up front
|
||||||
|
assert cat.rowCount() < 300
|
||||||
|
cat.fetchMore()
|
||||||
|
assert cat.rowCount() == 300
|
||||||
|
|
||||||
|
hist.delete('url', '298')
|
||||||
|
cat.removeRows(297, 1)
|
||||||
|
assert cat.rowCount() == 299
|
||||||
|
Loading…
Reference in New Issue
Block a user