diff --git a/qutebrowser/browser/history.py b/qutebrowser/browser/history.py index 9948992ea..2d5c263bc 100644 --- a/qutebrowser/browser/history.py +++ b/qutebrowser/browser/history.py @@ -84,12 +84,12 @@ class WebHistory(sql.SqlTable): data = {'url': [], 'title': [], 'last_atime': []} # select the latest entry for each url q = sql.Query('SELECT url, title, max(atime) AS atime FROM History ' - 'WHERE NOT redirect GROUP BY url') + 'WHERE NOT redirect GROUP BY url ORDER BY atime asc') for entry in q.run(): data['url'].append(self._format_completion_url(QUrl(entry.url))) data['title'].append(entry.title) data['last_atime'].append(entry.atime) - self.completion.insert_batch(data) + self.completion.insert_batch(data, replace=True) sql.Query('pragma user_version = {}'.format(_USER_VERSION)).run() def get_recent(self): diff --git a/tests/unit/browser/test_history.py b/tests/unit/browser/test_history.py index b49a52a2a..2462a1141 100644 --- a/tests/unit/browser/test_history.py +++ b/tests/unit/browser/test_history.py @@ -356,16 +356,22 @@ def test_debug_dump_history_nonexistent(hist, tmpdir): def test_rebuild_completion(hist): - hist.add_url(QUrl('example.com/1'), redirect=False, atime=1) - hist.add_url(QUrl('example.com/1'), redirect=False, atime=2) - hist.add_url(QUrl('example.com/2%203'), redirect=False, atime=3) - hist.add_url(QUrl('example.com/3'), redirect=True, atime=4) + hist.insert({'url': 'example.com/1', 'title': 'example1', + 'redirect': False, 'atime': 1}) + hist.insert({'url': 'example.com/1', 'title': 'example1', + 'redirect': False, 'atime': 2}) + hist.insert({'url': 'example.com/2%203', 'title': 'example2', + 'redirect': False, 'atime': 3}) + hist.insert({'url': 'example.com/3', 'title': 'example3', + 'redirect': True, 'atime': 4}) + hist.insert({'url': 'example.com/2 3', 'title': 'example2', + 'redirect': False, 'atime': 5}) hist.completion.delete_all() hist2 = history.WebHistory() assert list(hist2.completion) == [ - ('example.com/1', '', 2), - ('example.com/2 3', '', 3), + ('example.com/1', 'example1', 2), + ('example.com/2 3', 'example2', 5), ]