Merge lp:~stolowski/unity-scope-click/remove-assertion-and-old-api-fallback into lp:unity-scope-click/devel

Proposed by Paweł Stołowski
Status: Merged
Approved by: dobey
Approved revision: 354
Merged at revision: 356
Proposed branch: lp:~stolowski/unity-scope-click/remove-assertion-and-old-api-fallback
Merge into: lp:unity-scope-click/devel
Diff against target: 137 lines (+23/-34)
3 files modified
scope/clickstore/store-query.cpp (+23/-18)
scope/clickstore/store-scope.cpp (+0/-12)
scope/clickstore/store-scope.h (+0/-4)
To merge this branch: bzr merge lp:~stolowski/unity-scope-click/remove-assertion-and-old-api-fallback
Reviewer Review Type Date Requested Status
dobey (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+227719@code.launchpad.net

Commit message

Remove fallback to old server API if highlights call fails, this was needed only initially when server was not ready. Ensure we call ad highlights only if there was no network error (check general status, not the http code). Replaced assert with warning and early return.

Description of the change

Remove fallback to old server API if highlights call fails, this was needed only initially when server was not ready. Ensure we call ad highlights only if there was no network error (check general status, not the http code). Replaced assert with warning and early return.

No new tests, since this is existing functionality and this change makes it more robust.

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
dobey (dobey) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'scope/clickstore/store-query.cpp'
2--- scope/clickstore/store-query.cpp 2014-07-21 20:49:18 +0000
3+++ scope/clickstore/store-query.cpp 2014-07-22 12:43:58 +0000
4@@ -357,11 +357,16 @@
5 void click::Query::add_highlights(scopes::SearchReplyProxy const& searchReply, const PackageSet& locallyInstalledApps)
6 {
7 auto curdep = impl->department_lookup.get_department_info(query().department_id());
8- assert(curdep);
9- auto subdepts = curdep->sub_departments();
10+ if (!curdep)
11+ {
12+ qWarning() << "No department information for current department" << QString::fromStdString(query().department_id());
13+ return;
14+ }
15+
16 if (query().department_id() == "") // top-level departments
17 {
18 unity::scopes::Department::SPtr root;
19+ auto subdepts = curdep->sub_departments();
20 populate_departments(subdepts, query().department_id(), root);
21 push_departments(searchReply, root);
22
23@@ -396,6 +401,8 @@
24 const PackageSet& installedPackages,
25 const std::string& categoryTemplate)
26 {
27+ // this assertion is here to ensure unit tests are properly implemented.
28+ // this pointer is never null during normal execution.
29 assert(searchReply);
30
31 run_under_qt([=]()
32@@ -437,11 +444,11 @@
33 };
34
35 // this is the case when we do bootstrap for the first time, or it failed last time
36- if (impl->department_lookup.size() == 0 && !click::Scope::use_old_api())
37+ if (impl->department_lookup.size() == 0)
38 {
39 qDebug() << "performing bootstrap request";
40 impl->search_operation = impl->index.bootstrap([this, search_cb, searchReply, installedPackages](const DepartmentList& deps, const
41- HighlightList& highlights, click::Index::Error error, int error_code) {
42+ HighlightList& highlights, click::Index::Error error, int) {
43 if (error == click::Index::Error::NoError)
44 {
45 qDebug() << "bootstrap request completed";
46@@ -465,27 +472,25 @@
47 else
48 {
49 qWarning() << "bootstrap request failed";
50- if (error_code == 405 || error_code == 404) // method not allowed or resource not found
51- {
52- qDebug() << "bootstrap not available, using old API";
53- click::Scope::set_use_old_api();
54- }
55 }
56
57- if (query().query_string().empty() && !click::Scope::use_old_api() && error_code == 0)
58- {
59- add_highlights(searchReply, installedPackages);
60- }
61- else
62- {
63- qDebug() << "starting search of" << QString::fromStdString(query().query_string());
64- impl->search_operation = impl->index.search(query().query_string(), search_cb);
65+ if (error == click::Index::Error::NoError)
66+ {
67+ if (query().query_string().empty())
68+ {
69+ add_highlights(searchReply, installedPackages);
70+ }
71+ else
72+ {
73+ qDebug() << "starting search of" << QString::fromStdString(query().query_string());
74+ impl->search_operation = impl->index.search(query().query_string(), search_cb);
75+ }
76 }
77 });
78 }
79 else
80 {
81- if (query().query_string().empty() && !click::Scope::use_old_api())
82+ if (query().query_string().empty())
83 {
84 add_highlights(searchReply, installedPackages);
85 }
86
87=== modified file 'scope/clickstore/store-scope.cpp'
88--- scope/clickstore/store-scope.cpp 2014-07-18 15:01:41 +0000
89+++ scope/clickstore/store-scope.cpp 2014-07-22 12:43:58 +0000
90@@ -45,8 +45,6 @@
91 #include <logging.h>
92 #include <iostream>
93
94-bool click::Scope::old_api = false;
95-
96 click::Scope::Scope()
97 {
98 nam.reset(new click::network::AccessManager());
99@@ -70,16 +68,6 @@
100 {
101 }
102
103-void click::Scope::set_use_old_api()
104-{
105- old_api = true;
106-}
107-
108-bool click::Scope::use_old_api()
109-{
110- return old_api;
111-}
112-
113 void click::Scope::start(std::string const&, scopes::RegistryProxy const&)
114 {
115 setlocale(LC_ALL, "");
116
117=== modified file 'scope/clickstore/store-scope.h'
118--- scope/clickstore/store-scope.h 2014-07-16 21:49:11 +0000
119+++ scope/clickstore/store-scope.h 2014-07-22 12:43:58 +0000
120@@ -67,9 +67,6 @@
121
122 virtual unity::scopes::ActivationQueryBase::UPtr perform_action(unity::scopes::Result const& result, unity::scopes::ActionMetadata const& metadata, std::string const& widget_id, std::string const& action_id) override;
123
124- static void set_use_old_api();
125- static bool use_old_api();
126-
127 private:
128 QSharedPointer<click::network::AccessManager> nam;
129 QSharedPointer<click::web::Client> client;
130@@ -80,7 +77,6 @@
131 std::shared_ptr<pay::Package> pay_package;
132
133 std::string installApplication(unity::scopes::Result const& result);
134- static bool old_api;
135 };
136 }
137 #endif // CLICK_SCOPE_H

Subscribers

People subscribed via source and target branches

to all changes: