Merge lp:~stolowski/unity-scopes-shell/no-unlimited-categories into lp:unity-scopes-shell

Proposed by Paweł Stołowski
Status: Merged
Approved by: Marcus Tomlinson
Approved revision: 264
Merged at revision: 267
Proposed branch: lp:~stolowski/unity-scopes-shell/no-unlimited-categories
Merge into: lp:unity-scopes-shell
Diff against target: 39 lines (+22/-0)
1 file modified
src/Unity/categories.cpp (+22/-0)
To merge this branch: bzr merge lp:~stolowski/unity-scopes-shell/no-unlimited-categories
Reviewer Review Type Date Requested Status
Marcus Tomlinson (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+275031@code.launchpad.net

Commit message

Remove excess empty categories.

Description of the change

Remove excess empty categories.

Automated test for this change is hard to implement because scope harness abstracts away the low-level aspects of the models. I've tested manually (it's in silo 24) - after several refreshes of 'NearBy' scope (which currently produces categories with unique ids on every search) one can see the following debug message in dash log:

Purging unused category: "wn1:declared:first_result:surface_template::surface21.10.2015_10:29:46:113"
Purging unused category: "yelp1:declared:first_result:surface_template::surface21.10.2015_10:29:46:110"
Purging unused category: "yelp1_landmarks:declared:first_result:surface_template::surface21.10.2015_10:29:46:105"

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Marcus Tomlinson (marcustomlinson) wrote :

Looks good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Unity/categories.cpp'
2--- src/Unity/categories.cpp 2015-09-08 12:32:05 +0000
3+++ src/Unity/categories.cpp 2015-10-20 13:31:45 +0000
4@@ -38,6 +38,8 @@
5
6 namespace scopes_ng {
7
8+const int MAX_NUMBER_OF_CATEGORIES = 32; // when reached, any excess categories which have no results will be removed
9+
10 // FIXME: this should be in a common place
11 #define CATEGORY_JSON_DEFAULTS R"({"schema-version":1,"template": {"category-layout":"grid","card-layout":"vertical","card-size":"small","overlay-mode":null,"collapsed-rows":2}, "components": { "title":null, "art": { "aspect-ratio":1.0 }, "subtitle":null, "mascot":null, "emblem":null, "summary":null, "attributes": { "max-count":2 }, "background":null, "overlay-color":null }, "resources":{}})"
12
13@@ -403,6 +405,26 @@
14
15 endInsertRows();
16 }
17+
18+ if (m_categories.count() >= MAX_NUMBER_OF_CATEGORIES) {
19+ // we register one category at a time, so there can be one excess category at most
20+ const int index = m_categories.count() - 1;
21+ auto it = m_categories.begin() + index;
22+ if ((*it)->resultsModelCount() == 0) {
23+ qDebug() << "Purging unused category:" << (*it)->categoryId();
24+ beginRemoveRows(QModelIndex(), index, index);
25+ m_categoryResults.remove((*it)->categoryId().toStdString());
26+ for (auto kv = m_countObjects.begin(); kv != m_countObjects.end(); ++kv) {
27+ if (kv.value() == (*it)->categoryId()) {
28+ kv.key()->deleteLater();
29+ m_countObjects.erase(kv);
30+ break;
31+ }
32+ }
33+ m_categories.erase(it);
34+ endRemoveRows();
35+ }
36+ }
37 }
38
39 void Categories::updateResultCount(const QSharedPointer<ResultsModel>& resultsModel)

Subscribers

People subscribed via source and target branches

to all changes: