Merge lp:~fboucault/webbrowser-app/history_domain_no_extra_sorting into lp:webbrowser-app/staging

Proposed by Florian Boucault
Status: Approved
Approved by: Andrew Hayzen
Approved revision: 1629
Proposed branch: lp:~fboucault/webbrowser-app/history_domain_no_extra_sorting
Merge into: lp:webbrowser-app/staging
Diff against target: 165 lines (+38/-16)
4 files modified
src/app/webbrowser/HistoryView.qml (+2/-6)
src/app/webbrowser/history-domainlist-model.cpp (+27/-4)
src/app/webbrowser/history-domainlist-model.h (+3/-0)
tests/unittests/history-domainlist-model/tst_HistoryDomainListModelTests.cpp (+6/-6)
To merge this branch: bzr merge lp:~fboucault/webbrowser-app/history_domain_no_extra_sorting
Reviewer Review Type Date Requested Status
Andrew Hayzen (community) Approve
Review via email: mp+319199@code.launchpad.net

Commit message

HistoryDomainListModel: preserve order of insertion which is de facto by 'lastVisit'. That makes it possible to not use an extra SortFilterModel in HistoryView which was slowing down loading dramatically when enough history is gathered.

Description of the change

HistoryDomainListModel: preserve order of insertion which is de facto by 'lastVisit'. That makes it possible to not use an extra SortFilterModel in HistoryView which was slowing down loading dramatically when enough history is gathered.

To post a comment you must log in.
Revision history for this message
Andrew Hayzen (ahayzen) wrote :

I'm getting the following two failures with this branch that I wasn't getting in staging.

2: QWARN : QmlTests::HistoryView::test_delete_multiple_domains() file:///tmp/webbrowser/history_domain_no_extra_sorting/src/app/webbrowser/HistoryView.qml:179: TypeError: Property 'get' of object HistoryDomainListModel(0x146be40) is not a function
2: FAIL! : QmlTests::HistoryView::test_delete_multiple_domains() property selectMode
2: Actual (): true
2: Expected (): false
2: Loc: [/tmp/webbrowser/history_domain_no_extra_sorting/tests/unittests/qml/tst_HistoryView.qml(153)]

2: QWARN : QmlTests::HistoryView::test_select_all() file:///tmp/webbrowser/history_domain_no_extra_sorting/src/app/webbrowser/HistoryView.qml:179: TypeError: Property 'get' of object HistoryDomainListModel(0x1c73c70) is not a function
2: FAIL! : QmlTests::HistoryView::test_select_all() property count
2: Actual (): 3
2: Expected (): 0
2: Loc: [/tmp/webbrowser/history_domain_no_extra_sorting/tests/unittests/qml/tst_HistoryView.qml(190)]

Also note in both this branch and staging flake8 fails for me with the following, looks like a regression has slipped into staging. (this issue can be fixed in another branch or in this one)

1: /tmp/webbrowser/staging/tests/autopilot/webbrowser_app/tests/test_fullscreen.py:102:1: E302 expected 2 blank lines, found 1
1: /tmp/webbrowser/staging/tests/autopilot/webbrowser_app/tests/test_fullscreen.py:106:80: E501 line too long (82 > 79 characters)

review: Needs Fixing
1628. By Florian Boucault

Merged from staging

1629. By Florian Boucault

Added HistoryDomainListModel::get: fixes unit tests HistoryView::test_delete_multiple_domains and HistoryView::test_select_all

Revision history for this message
Andrew Hayzen (ahayzen) wrote :

Doing some testing on a Nexus 4 (mako) :-)
I found the following speed improvements when opening the history view:

stock
1st time: 12 seconds
2nd time: 9.8 seconds
3rd time: 9.6 seconds

this branch
1st time: 8 seconds
2nd time: 6.3 seconds
3rd time: 6.2 seconds

So this branch has resulted in a reduction of 1/3 of the overall time :-)

Revision history for this message
Florian Boucault (fboucault) wrote :

> Doing some testing on a Nexus 4 (mako) :-)
> I found the following speed improvements when opening the history view:
>
> stock
> 1st time: 12 seconds
> 2nd time: 9.8 seconds
> 3rd time: 9.6 seconds
>
>
> this branch
> 1st time: 8 seconds
> 2nd time: 6.3 seconds
> 3rd time: 6.2 seconds
>
> So this branch has resulted in a reduction of 1/3 of the overall time :-)

Hmmm, not good enough

Revision history for this message
Andrew Hayzen (ahayzen) wrote :

LGTM, all unit tests now pass and functionally it looks good :-)

I have found one issue that looks like it is also in staging, so not created by this branch.
1) Open the history view
2) Scroll up/down, notice the scrolling works
3) Delete something from the history using the right click menu
4) Scroll up/down, notice the scrolling doesn't work, and if you click back in the header the scrolling is broken in the webview and you can't click to change tabs etc.

review: Approve
Revision history for this message
flohack (flori-bin) wrote :

Unmerged revisions

1629. By Florian Boucault

Added HistoryDomainListModel::get: fixes unit tests HistoryView::test_delete_multiple_domains and HistoryView::test_select_all

1628. By Florian Boucault

Merged from staging

1627. By Florian Boucault

HistoryDomainListModel: preserve order of insertion which is de facto by 'lastVisit'. That makes it possible to not use an extra SortFilterModel in HistoryView which was slowing down loading dramatically when enough history is gathered.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/app/webbrowser/HistoryView.qml'
--- src/app/webbrowser/HistoryView.qml 2016-06-06 09:09:47 +0000
+++ src/app/webbrowser/HistoryView.qml 2017-03-08 12:26:13 +0000
@@ -57,12 +57,8 @@
57 bottom: toolbar.top57 bottom: toolbar.top
58 }58 }
5959
60 model: SortFilterModel {60 model: HistoryDomainListModel {
61 model: HistoryDomainListModel {61 id: historyDomainListModel
62 id: historyDomainListModel
63 }
64 sort.property: "lastVisit"
65 sort.order: Qt.DescendingOrder
66 }62 }
6763
68 section.property: "lastVisitDate"64 section.property: "lastVisitDate"
6965
=== modified file 'src/app/webbrowser/history-domainlist-model.cpp'
--- src/app/webbrowser/history-domainlist-model.cpp 2015-10-28 21:50:08 +0000
+++ src/app/webbrowser/history-domainlist-model.cpp 2017-03-08 12:26:13 +0000
@@ -69,7 +69,7 @@
69 if (!index.isValid()) {69 if (!index.isValid()) {
70 return QVariant();70 return QVariant();
71 }71 }
72 const QString domain = m_domains.keys().at(index.row());72 const QString domain = m_domainsPerLastVisit.at(index.row());
73 HistoryDomainModel* entries = m_domains.value(domain);73 HistoryDomainModel* entries = m_domains.value(domain);
7474
75 switch (role) {75 switch (role) {
@@ -117,11 +117,32 @@
117 }117 }
118}118}
119119
120QVariantMap HistoryDomainListModel::get(int row) const
121{
122 if (row < 0 || row >= rowCount()) {
123 return QVariantMap();
124 }
125
126 QVariantMap res;
127 QHash<int,QByteArray> names = roleNames();
128 QHashIterator<int, QByteArray> i(names);
129
130 while (i.hasNext()) {
131 i.next();
132 QModelIndex idx = index(row, 0);
133 QVariant data = idx.data(i.key());
134 res[i.value()] = data;
135 }
136
137 return res;
138}
139
120void HistoryDomainListModel::clearDomains()140void HistoryDomainListModel::clearDomains()
121{141{
122 Q_FOREACH(const QString& domain, m_domains.keys()) {142 Q_FOREACH(const QString& domain, m_domains.keys()) {
123 delete m_domains.take(domain);143 delete m_domains.take(domain);
124 }144 }
145 m_domainsPerLastVisit.clear();
125}146}
126147
127void HistoryDomainListModel::populateModel()148void HistoryDomainListModel::populateModel()
@@ -142,7 +163,7 @@
142 for (int i = start; i <= end; ++i) {163 for (int i = start; i <= end; ++i) {
143 QString domain = getDomainFromSourceModel(m_sourceModel->index(i, 0, parent));164 QString domain = getDomainFromSourceModel(m_sourceModel->index(i, 0, parent));
144 if (!m_domains.contains(domain)) {165 if (!m_domains.contains(domain)) {
145 QStringList domains = m_domains.keys();166 QStringList domains = m_domainsPerLastVisit;
146 int insertAt = 0;167 int insertAt = 0;
147 while (insertAt < domains.count()) {168 while (insertAt < domains.count()) {
148 if (domain.compare(domains.at(insertAt)) < 0) {169 if (domain.compare(domains.at(insertAt)) < 0) {
@@ -178,6 +199,7 @@
178 connect(model, SIGNAL(modelReset()), SLOT(onDomainDataChanged()));199 connect(model, SIGNAL(modelReset()), SLOT(onDomainDataChanged()));
179 connect(model, SIGNAL(lastVisitChanged()), SLOT(onDomainDataChanged()));200 connect(model, SIGNAL(lastVisitChanged()), SLOT(onDomainDataChanged()));
180 m_domains.insert(domain, model);201 m_domains.insert(domain, model);
202 m_domainsPerLastVisit.append(domain);
181}203}
182204
183QString HistoryDomainListModel::getDomainFromSourceModel(const QModelIndex& index) const205QString HistoryDomainListModel::getDomainFromSourceModel(const QModelIndex& index) const
@@ -194,9 +216,10 @@
194 if (model != 0) {216 if (model != 0) {
195 const QString& domain = model->domain();217 const QString& domain = model->domain();
196 if (model->rowCount() == 0) {218 if (model->rowCount() == 0) {
197 int removeAt = m_domains.keys().indexOf(domain);219 int removeAt = m_domainsPerLastVisit.indexOf(domain);
198 beginRemoveRows(QModelIndex(), removeAt, removeAt);220 beginRemoveRows(QModelIndex(), removeAt, removeAt);
199 delete m_domains.take(domain);221 delete m_domains.take(domain);
222 m_domainsPerLastVisit.removeAt(removeAt);
200 endRemoveRows();223 endRemoveRows();
201 } else {224 } else {
202 emitDataChanged(domain);225 emitDataChanged(domain);
@@ -214,7 +237,7 @@
214237
215void HistoryDomainListModel::emitDataChanged(const QString& domain)238void HistoryDomainListModel::emitDataChanged(const QString& domain)
216{239{
217 int i = m_domains.keys().indexOf(domain);240 int i = m_domainsPerLastVisit.indexOf(domain);
218 if (i != -1) {241 if (i != -1) {
219 QModelIndex index = this->index(i, 0);242 QModelIndex index = this->index(i, 0);
220 Q_EMIT dataChanged(index, index, QVector<int>() << LastVisit << LastVisitDate << LastVisitedTitle << LastVisitedIcon << Entries);243 Q_EMIT dataChanged(index, index, QVector<int>() << LastVisit << LastVisitDate << LastVisitedTitle << LastVisitedIcon << Entries);
221244
=== modified file 'src/app/webbrowser/history-domainlist-model.h'
--- src/app/webbrowser/history-domainlist-model.h 2015-10-28 21:50:08 +0000
+++ src/app/webbrowser/history-domainlist-model.h 2017-03-08 12:26:13 +0000
@@ -56,6 +56,8 @@
56 HistoryModel* sourceModel() const;56 HistoryModel* sourceModel() const;
57 void setSourceModel(HistoryModel* sourceModel);57 void setSourceModel(HistoryModel* sourceModel);
5858
59 Q_INVOKABLE QVariantMap get(int row) const;
60
59Q_SIGNALS:61Q_SIGNALS:
60 void sourceModelChanged() const;62 void sourceModelChanged() const;
6163
@@ -69,6 +71,7 @@
69private:71private:
70 HistoryModel* m_sourceModel;72 HistoryModel* m_sourceModel;
71 QMap<QString, HistoryDomainModel*> m_domains;73 QMap<QString, HistoryDomainModel*> m_domains;
74 QStringList m_domainsPerLastVisit;
7275
73 void clearDomains();76 void clearDomains();
74 void populateModel();77 void populateModel();
7578
=== modified file 'tests/unittests/history-domainlist-model/tst_HistoryDomainListModelTests.cpp'
--- tests/unittests/history-domainlist-model/tst_HistoryDomainListModelTests.cpp 2015-10-28 21:50:08 +0000
+++ tests/unittests/history-domainlist-model/tst_HistoryDomainListModelTests.cpp 2017-03-08 12:26:13 +0000
@@ -89,14 +89,14 @@
89 QCOMPARE(args.at(1).toInt(), 0);89 QCOMPARE(args.at(1).toInt(), 0);
90 QCOMPARE(args.at(2).toInt(), 0);90 QCOMPARE(args.at(2).toInt(), 0);
91 QCOMPARE(model->rowCount(), 2);91 QCOMPARE(model->rowCount(), 2);
92 QCOMPARE(model->data(model->index(0, 0), HistoryDomainListModel::Domain).toString(), QString("example.com"));92 QCOMPARE(model->data(model->index(1, 0), HistoryDomainListModel::Domain).toString(), QString("example.com"));
9393
94 history->add(QUrl("http://example.org/test.html"), "Test page", QUrl());94 history->add(QUrl("http://example.org/test.html"), "Test page", QUrl());
95 QVERIFY(spyRowsInserted.isEmpty());95 QVERIFY(spyRowsInserted.isEmpty());
96 QVERIFY(!spyDataChanged.isEmpty());96 QVERIFY(!spyDataChanged.isEmpty());
97 args = spyDataChanged.takeFirst();97 args = spyDataChanged.takeFirst();
98 QCOMPARE(args.at(0).toModelIndex().row(), 1);98 QCOMPARE(args.at(0).toModelIndex().row(), 0);
99 QCOMPARE(args.at(1).toModelIndex().row(), 1);99 QCOMPARE(args.at(1).toModelIndex().row(), 0);
100 QCOMPARE(model->rowCount(), 2);100 QCOMPARE(model->rowCount(), 2);
101 }101 }
102102
@@ -171,7 +171,7 @@
171 QCOMPARE(model->rowCount(), 0);171 QCOMPARE(model->rowCount(), 0);
172 }172 }
173173
174 void shouldKeepDomainsSorted()174 void shouldKeepDomainsSortedInsertionOrder()
175 {175 {
176 history->add(QUrl("http://example.org/"), "Example Domain", QUrl());176 history->add(QUrl("http://example.org/"), "Example Domain", QUrl());
177 history->add(QUrl("http://www.gogle.com/lawnmower"), "Gogle Lawn Mower", QUrl());177 history->add(QUrl("http://www.gogle.com/lawnmower"), "Gogle Lawn Mower", QUrl());
@@ -183,8 +183,8 @@
183 history->add(QUrl("https://es.wikipedia.org/wiki/Wikipedia:Portada"), "Wikipedia, la enciclopedia libre", QUrl());183 history->add(QUrl("https://es.wikipedia.org/wiki/Wikipedia:Portada"), "Wikipedia, la enciclopedia libre", QUrl());
184 QCOMPARE(model->rowCount(), 6);184 QCOMPARE(model->rowCount(), 6);
185 QStringList domains;185 QStringList domains;
186 domains << DomainUtils::TOKEN_LOCAL << "example.com" << "example.org"186 domains << "example.org" << "gogle.com" << "example.com" << "ubuntu.com"
187 << "gogle.com" << "ubuntu.com" << "wikipedia.org";187 << DomainUtils::TOKEN_LOCAL << "wikipedia.org";
188 for (int i = 0; i < domains.count(); ++i) {188 for (int i = 0; i < domains.count(); ++i) {
189 QModelIndex index = model->index(i, 0);189 QModelIndex index = model->index(i, 0);
190 QString domain = model->data(index, HistoryDomainListModel::Domain).toString();190 QString domain = model->data(index, HistoryDomainListModel::Domain).toString();

Subscribers

People subscribed via source and target branches