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
=== modified file 'scope/clickstore/store-query.cpp'
--- scope/clickstore/store-query.cpp 2014-07-21 20:49:18 +0000
+++ scope/clickstore/store-query.cpp 2014-07-22 12:43:58 +0000
@@ -357,11 +357,16 @@
357void click::Query::add_highlights(scopes::SearchReplyProxy const& searchReply, const PackageSet& locallyInstalledApps)357void click::Query::add_highlights(scopes::SearchReplyProxy const& searchReply, const PackageSet& locallyInstalledApps)
358{358{
359 auto curdep = impl->department_lookup.get_department_info(query().department_id());359 auto curdep = impl->department_lookup.get_department_info(query().department_id());
360 assert(curdep);360 if (!curdep)
361 auto subdepts = curdep->sub_departments();361 {
362 qWarning() << "No department information for current department" << QString::fromStdString(query().department_id());
363 return;
364 }
365
362 if (query().department_id() == "") // top-level departments366 if (query().department_id() == "") // top-level departments
363 {367 {
364 unity::scopes::Department::SPtr root;368 unity::scopes::Department::SPtr root;
369 auto subdepts = curdep->sub_departments();
365 populate_departments(subdepts, query().department_id(), root);370 populate_departments(subdepts, query().department_id(), root);
366 push_departments(searchReply, root);371 push_departments(searchReply, root);
367372
@@ -396,6 +401,8 @@
396 const PackageSet& installedPackages,401 const PackageSet& installedPackages,
397 const std::string& categoryTemplate)402 const std::string& categoryTemplate)
398{403{
404 // this assertion is here to ensure unit tests are properly implemented.
405 // this pointer is never null during normal execution.
399 assert(searchReply);406 assert(searchReply);
400407
401 run_under_qt([=]()408 run_under_qt([=]()
@@ -437,11 +444,11 @@
437 };444 };
438445
439 // this is the case when we do bootstrap for the first time, or it failed last time446 // this is the case when we do bootstrap for the first time, or it failed last time
440 if (impl->department_lookup.size() == 0 && !click::Scope::use_old_api())447 if (impl->department_lookup.size() == 0)
441 {448 {
442 qDebug() << "performing bootstrap request";449 qDebug() << "performing bootstrap request";
443 impl->search_operation = impl->index.bootstrap([this, search_cb, searchReply, installedPackages](const DepartmentList& deps, const450 impl->search_operation = impl->index.bootstrap([this, search_cb, searchReply, installedPackages](const DepartmentList& deps, const
444 HighlightList& highlights, click::Index::Error error, int error_code) {451 HighlightList& highlights, click::Index::Error error, int) {
445 if (error == click::Index::Error::NoError)452 if (error == click::Index::Error::NoError)
446 {453 {
447 qDebug() << "bootstrap request completed";454 qDebug() << "bootstrap request completed";
@@ -465,27 +472,25 @@
465 else472 else
466 {473 {
467 qWarning() << "bootstrap request failed";474 qWarning() << "bootstrap request failed";
468 if (error_code == 405 || error_code == 404) // method not allowed or resource not found
469 {
470 qDebug() << "bootstrap not available, using old API";
471 click::Scope::set_use_old_api();
472 }
473 }475 }
474476
475 if (query().query_string().empty() && !click::Scope::use_old_api() && error_code == 0)477 if (error == click::Index::Error::NoError)
476 {478 {
477 add_highlights(searchReply, installedPackages);479 if (query().query_string().empty())
478 }480 {
479 else481 add_highlights(searchReply, installedPackages);
480 {482 }
481 qDebug() << "starting search of" << QString::fromStdString(query().query_string());483 else
482 impl->search_operation = impl->index.search(query().query_string(), search_cb);484 {
485 qDebug() << "starting search of" << QString::fromStdString(query().query_string());
486 impl->search_operation = impl->index.search(query().query_string(), search_cb);
487 }
483 }488 }
484 });489 });
485 }490 }
486 else491 else
487 {492 {
488 if (query().query_string().empty() && !click::Scope::use_old_api())493 if (query().query_string().empty())
489 {494 {
490 add_highlights(searchReply, installedPackages);495 add_highlights(searchReply, installedPackages);
491 }496 }
492497
=== modified file 'scope/clickstore/store-scope.cpp'
--- scope/clickstore/store-scope.cpp 2014-07-18 15:01:41 +0000
+++ scope/clickstore/store-scope.cpp 2014-07-22 12:43:58 +0000
@@ -45,8 +45,6 @@
45#include <logging.h>45#include <logging.h>
46#include <iostream>46#include <iostream>
4747
48bool click::Scope::old_api = false;
49
50click::Scope::Scope()48click::Scope::Scope()
51{49{
52 nam.reset(new click::network::AccessManager());50 nam.reset(new click::network::AccessManager());
@@ -70,16 +68,6 @@
70{68{
71}69}
7270
73void click::Scope::set_use_old_api()
74{
75 old_api = true;
76}
77
78bool click::Scope::use_old_api()
79{
80 return old_api;
81}
82
83void click::Scope::start(std::string const&, scopes::RegistryProxy const&)71void click::Scope::start(std::string const&, scopes::RegistryProxy const&)
84{72{
85 setlocale(LC_ALL, "");73 setlocale(LC_ALL, "");
8674
=== modified file 'scope/clickstore/store-scope.h'
--- scope/clickstore/store-scope.h 2014-07-16 21:49:11 +0000
+++ scope/clickstore/store-scope.h 2014-07-22 12:43:58 +0000
@@ -67,9 +67,6 @@
6767
68 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;68 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;
6969
70 static void set_use_old_api();
71 static bool use_old_api();
72
73private:70private:
74 QSharedPointer<click::network::AccessManager> nam;71 QSharedPointer<click::network::AccessManager> nam;
75 QSharedPointer<click::web::Client> client;72 QSharedPointer<click::web::Client> client;
@@ -80,7 +77,6 @@
80 std::shared_ptr<pay::Package> pay_package;77 std::shared_ptr<pay::Package> pay_package;
8178
82 std::string installApplication(unity::scopes::Result const& result);79 std::string installApplication(unity::scopes::Result const& result);
83 static bool old_api;
84};80};
85}81}
86#endif // CLICK_SCOPE_H82#endif // CLICK_SCOPE_H

Subscribers

People subscribed via source and target branches

to all changes: