Merge lp:~stolowski/unity-scope-click/clear-cache-on-lang-change into lp:unity-scope-click
- clear-cache-on-lang-change
- Merge into trunk
Proposed by
Paweł Stołowski
Status: | Superseded |
---|---|
Proposed branch: | lp:~stolowski/unity-scope-click/clear-cache-on-lang-change |
Merge into: | lp:unity-scope-click |
Diff against target: |
759 lines (+184/-63) 15 files modified
CMakeLists.txt (+3/-0) libclickscope/click/index.cpp (+12/-8) libclickscope/click/index.h (+6/-4) libclickscope/click/network_access_manager.cpp (+82/-5) libclickscope/click/network_access_manager.h (+2/-1) libclickscope/click/preview.cpp (+28/-17) libclickscope/click/preview.h (+6/-1) libclickscope/click/reviews.cpp (+3/-2) libclickscope/click/reviews.h (+2/-1) libclickscope/click/webclient.cpp (+10/-4) libclickscope/click/webclient.h (+2/-2) libclickscope/tests/mock_webclient.h (+2/-2) libclickscope/tests/test_preview.cpp (+16/-9) scope/clickstore/store-query.cpp (+7/-5) scope/tests/test_helpers.h (+3/-2) |
To merge this branch: | bzr merge lp:~stolowski/unity-scope-click/clear-cache-on-lang-change |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
PS Jenkins bot | continuous-integration | Needs Fixing | |
Unity API Team | Pending | ||
Review via email: mp+293884@code.launchpad.net |
This proposal has been superseded by a proposal from 2016-05-06.
Commit message
Clear network cache if language was changed
Description of the change
Clear network cache if language was changed
To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : | # |
review:
Needs Fixing
(continuous-integration)
- 447. By Paweł Stołowski
-
Added fixme comment
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:447
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
review:
Needs Fixing
(continuous-integration)
- 448. By Paweł Stołowski
-
Moved to network access manager
- 449. By Paweł Stołowski
-
Merged network-timestamps
Unmerged revisions
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'CMakeLists.txt' |
2 | --- CMakeLists.txt 2016-02-24 14:55:08 +0000 |
3 | +++ CMakeLists.txt 2016-05-06 14:29:14 +0000 |
4 | @@ -27,6 +27,9 @@ |
5 | pkg_check_modules(UNITY_SCOPES REQUIRED libunity-scopes>=0.6.7 libunity-api>=0.1.3) |
6 | add_definitions(${UNITY_SCOPES_CFLAGS} ${UNITY_SCOPES_CFLAGS_OTHER}) |
7 | |
8 | +# Uncomment to enable network timings messages via stderr |
9 | +# add_definitions(-DNETWORK_TIMINGS) |
10 | + |
11 | pkg_check_modules(UBUNTUONE REQUIRED ubuntuoneauth-2.0>=15.10) |
12 | add_definitions(${UBUNTUONE_CFLAGS} ${UBUNTUONE_CFLAGS_OTHER}) |
13 | |
14 | |
15 | === modified file 'libclickscope/click/index.cpp' |
16 | --- libclickscope/click/index.cpp 2016-03-23 21:04:12 +0000 |
17 | +++ libclickscope/click/index.cpp 2016-05-06 14:29:14 +0000 |
18 | @@ -148,13 +148,14 @@ |
19 | } |
20 | |
21 | click::web::Cancellable Index::search (const std::string& query, const std::string& department, |
22 | - std::function<void(click::Packages search_results, click::Packages recommendations)> callback) |
23 | + std::function<void(click::Packages search_results, click::Packages recommendations)> callback, |
24 | + bool force_cache) |
25 | { |
26 | click::web::CallParams params; |
27 | const std::string built_query(build_index_query(query, department)); |
28 | params.add(click::QUERY_ARGNAME, built_query.c_str()); |
29 | QSharedPointer<click::web::Response> response(client->call( |
30 | - get_base_url() + click::SEARCH_PATH, "GET", true, build_headers(), "", params)); |
31 | + get_base_url() + click::SEARCH_PATH, "GET", true, build_headers(), "", params, force_cache)); |
32 | |
33 | QObject::connect(response.data(), &click::web::Response::finished, [=](QString reply) { |
34 | std::pair<Packages, Packages> package_lists; |
35 | @@ -172,16 +173,17 @@ |
36 | return click::web::Cancellable(response); |
37 | } |
38 | |
39 | -click::web::Cancellable Index::bootstrap(std::function<void(const click::DepartmentList&, const click::HighlightList&, Error, int)> callback) |
40 | +click::web::Cancellable Index::bootstrap(std::function<void(const click::DepartmentList&, const click::HighlightList&, Error, int)> callback, bool force_cache) |
41 | { |
42 | - return departments(get_base_url() + click::BOOTSTRAP_PATH, callback); |
43 | + return departments(get_base_url() + click::BOOTSTRAP_PATH, callback, force_cache); |
44 | } |
45 | |
46 | -click::web::Cancellable Index::departments(const std::string& department_href, std::function<void(const DepartmentList&, const HighlightList&, Error, int)> callback) |
47 | +click::web::Cancellable Index::departments(const std::string& department_href, std::function<void(const DepartmentList&, const HighlightList&, Error, int)> |
48 | + callback, bool force_cache) |
49 | { |
50 | click::web::CallParams params; |
51 | QSharedPointer<click::web::Response> response(client->call( |
52 | - department_href, "GET", true, build_headers(), "", params)); |
53 | + department_href, "GET", true, build_headers(), "", params, force_cache)); |
54 | |
55 | QObject::connect(response.data(), &click::web::Response::finished, [=](QString reply) { |
56 | qDebug() << "departments request finished"; |
57 | @@ -213,10 +215,12 @@ |
58 | return click::web::Cancellable(response); |
59 | } |
60 | |
61 | -click::web::Cancellable Index::get_details (const std::string& package_name, std::function<void(PackageDetails, click::Index::Error)> callback) |
62 | +click::web::Cancellable Index::get_details (const std::string& package_name, std::function<void(PackageDetails, click::Index::Error)> callback, bool force_cache) |
63 | { |
64 | QSharedPointer<click::web::Response> response = client->call |
65 | - (get_base_url() + click::DETAILS_PATH + package_name); |
66 | + (get_base_url() + click::DETAILS_PATH + package_name, |
67 | + click::web::CallParams(), |
68 | + force_cache); |
69 | qDebug() << "getting details for" << package_name.c_str(); |
70 | |
71 | QObject::connect(response.data(), &click::web::Response::finished, [=](const QByteArray reply) { |
72 | |
73 | === modified file 'libclickscope/click/index.h' |
74 | --- libclickscope/click/index.h 2015-12-01 15:39:41 +0000 |
75 | +++ libclickscope/click/index.h 2016-05-06 14:29:14 +0000 |
76 | @@ -79,10 +79,12 @@ |
77 | Index(const QSharedPointer<click::web::Client>& client, |
78 | const QSharedPointer<Configuration> configuration=QSharedPointer<Configuration>(new Configuration())); |
79 | virtual std::pair<Packages, Packages> package_lists_from_json(const std::string& json); |
80 | - virtual click::web::Cancellable search (const std::string& query, const std::string& department, std::function<void(Packages, Packages)> callback); |
81 | - virtual click::web::Cancellable get_details(const std::string& package_name, std::function<void(PackageDetails, Error)> callback); |
82 | - virtual click::web::Cancellable bootstrap(std::function<void(const DepartmentList&, const HighlightList&, Error, int)> callback); |
83 | - virtual click::web::Cancellable departments(const std::string& department_href, std::function<void(const DepartmentList&, const HighlightList&, Error, int)> callback); |
84 | + virtual click::web::Cancellable search (const std::string& query, const std::string& department, std::function<void(Packages, Packages)> callback, bool |
85 | + force_cache = false); |
86 | + virtual click::web::Cancellable get_details(const std::string& package_name, std::function<void(PackageDetails, Error)> callback, bool force_cache = false); |
87 | + virtual click::web::Cancellable bootstrap(std::function<void(const DepartmentList&, const HighlightList&, Error, int)> callback, bool force_cache = false); |
88 | + virtual click::web::Cancellable departments(const std::string& department_href, std::function<void(const DepartmentList&, const HighlightList&, Error, int)> |
89 | + callback, bool force_cache = false); |
90 | virtual ~Index(); |
91 | |
92 | virtual std::string get_suggested_currency() const; |
93 | |
94 | === modified file 'libclickscope/click/network_access_manager.cpp' |
95 | --- libclickscope/click/network_access_manager.cpp 2014-08-11 11:18:49 +0000 |
96 | +++ libclickscope/click/network_access_manager.cpp 2016-05-06 14:29:14 +0000 |
97 | @@ -30,8 +30,14 @@ |
98 | #include "network_access_manager.h" |
99 | #include <QNetworkDiskCache> |
100 | #include <QStandardPaths> |
101 | +#include <click/configuration.h> |
102 | +#include <fstream> |
103 | +#include <sstream> |
104 | +#include <iostream> |
105 | +#include <QDateTime> |
106 | +#include <time.h> |
107 | |
108 | -click::network::Reply::Reply(QNetworkReply* reply) : reply(reply) |
109 | +click::network::Reply::Reply(QNetworkReply* reply, int id) : reply(reply) |
110 | { |
111 | connect(this->reply.data(), |
112 | &QNetworkReply::finished, |
113 | @@ -43,6 +49,25 @@ |
114 | static_cast<QNetworkReplyErrorSignal>(&QNetworkReply::error), |
115 | this, |
116 | &Reply::error); |
117 | + |
118 | +#ifdef NETWORK_TIMINGS |
119 | + auto url = reply->url().toString().toStdString(); |
120 | + connect(this->reply.data(), |
121 | + &QNetworkReply::finished, |
122 | + [url, id, reply] () { |
123 | + bool fromCache = reply->attribute(QNetworkRequest::SourceIsFromCacheAttribute).toBool(); |
124 | + std::cerr << ">> " << id << " " << QDateTime::currentMSecsSinceEpoch() << " FINISHED: " << url << " cache:" << fromCache << std::endl; |
125 | + }); |
126 | + |
127 | + |
128 | + connect(this->reply.data(), |
129 | + static_cast<QNetworkReplyErrorSignal>(&QNetworkReply::error), |
130 | + [url, id] () { |
131 | + std::cerr << ">> " << id << QDateTime::currentMSecsSinceEpoch() << " ERROR: " << url << std::endl; |
132 | + }); |
133 | +#else |
134 | + Q_UNUSED(id); |
135 | +#endif |
136 | } |
137 | |
138 | click::network::Reply::~Reply() |
139 | @@ -90,6 +115,7 @@ |
140 | |
141 | namespace |
142 | { |
143 | + |
144 | QNetworkAccessManager& networkAccessManagerInstance() |
145 | { |
146 | static QNetworkAccessManager nam; |
147 | @@ -98,27 +124,78 @@ |
148 | QNetworkDiskCache* cache = new QNetworkDiskCache(&nam); |
149 | cache->setCacheDirectory(QString("%1/unity-scope-click/network").arg(QStandardPaths::writableLocation(QStandardPaths::CacheLocation))); |
150 | nam.setCache(cache); |
151 | + |
152 | + // FIXME: workaround for https://bugreports.qt.io/browse/QTBUG-14750 (no support for Vary header), |
153 | + // should be removed once Qt network cache implements it. |
154 | + if (click::network::AccessManager::languageChanged()) { |
155 | + qDebug() << "Language change detected, clearing network cache"; |
156 | + nam.cache()->clear(); |
157 | + } |
158 | } |
159 | return nam; |
160 | } |
161 | } |
162 | |
163 | +bool click::network::AccessManager::languageChanged() |
164 | +{ |
165 | + const QString langFilePath = QString("%1/unity-scope-click/language").arg(QStandardPaths::writableLocation(QStandardPaths::CacheLocation)); |
166 | + std::string lastLanguage; |
167 | + { |
168 | + std::ifstream lastLanguageFile(langFilePath.toStdString()); |
169 | + if (lastLanguageFile) { |
170 | + std::stringstream ss; |
171 | + ss << lastLanguageFile.rdbuf(); |
172 | + lastLanguage = ss.str(); |
173 | + } |
174 | + } |
175 | + |
176 | + auto const langs = Configuration().get_accept_languages(); |
177 | + if (lastLanguage != langs) { |
178 | + std::ofstream lastLanguageFile(langFilePath.toStdString(), std::ios::out|std::ios::trunc); |
179 | + lastLanguageFile << langs; |
180 | + if (!lastLanguageFile) { |
181 | + qWarning() << "Failed to write language file"; |
182 | + } |
183 | + return true; |
184 | + } |
185 | + return false; |
186 | +} |
187 | + |
188 | +static int request_id = static_cast<int>(time(nullptr)); // this ensures request ids will be unique even if scope is restarted |
189 | + |
190 | QSharedPointer<click::network::Reply> click::network::AccessManager::get(QNetworkRequest& request) |
191 | { |
192 | - return QSharedPointer<click::network::Reply>(new click::network::Reply(networkAccessManagerInstance().get(request))); |
193 | + int id = ++request_id; |
194 | +#ifdef NETWORK_TIMINGS |
195 | + std::cerr << ">> " << id << " " << QDateTime::currentMSecsSinceEpoch() << " GET: " << request.url().toString().toStdString() << std::endl; |
196 | +#endif |
197 | + return QSharedPointer<click::network::Reply>(new click::network::Reply(networkAccessManagerInstance().get(request), id)); |
198 | } |
199 | |
200 | QSharedPointer<click::network::Reply> click::network::AccessManager::head(QNetworkRequest& request) |
201 | { |
202 | - return QSharedPointer<click::network::Reply>(new click::network::Reply(networkAccessManagerInstance().head(request))); |
203 | + int id = ++request_id; |
204 | +#ifdef NETWORK_TIMINGS |
205 | + std::cerr << ">> " << id << " " << QDateTime::currentMSecsSinceEpoch() << " HEAD: " << request.url().toString().toStdString() << std::endl; |
206 | +#endif |
207 | + return QSharedPointer<click::network::Reply>(new click::network::Reply(networkAccessManagerInstance().head(request), id)); |
208 | } |
209 | |
210 | QSharedPointer<click::network::Reply> click::network::AccessManager::post(QNetworkRequest& request, QByteArray& data) |
211 | { |
212 | - return QSharedPointer<click::network::Reply>(new click::network::Reply(networkAccessManagerInstance().post(request, data))); |
213 | + int id = ++request_id; |
214 | +#ifdef NETWORK_TIMINGS |
215 | + std::cerr << ">> " << id << " " << QDateTime::currentMSecsSinceEpoch() << " POST: " << request.url().toString().toStdString() << std::endl; |
216 | +#endif |
217 | + return QSharedPointer<click::network::Reply>(new click::network::Reply(networkAccessManagerInstance().post(request, data), id)); |
218 | } |
219 | |
220 | QSharedPointer<click::network::Reply> click::network::AccessManager::sendCustomRequest(QNetworkRequest& request, QByteArray& verb, QIODevice *data) |
221 | { |
222 | - return QSharedPointer<click::network::Reply>(new click::network::Reply(networkAccessManagerInstance().sendCustomRequest(request, verb, data))); |
223 | + int id = ++request_id; |
224 | +#ifdef NETWORK_TIMINGS |
225 | + std::cerr << ">> " << id << " " << QDateTime::currentMSecsSinceEpoch() << " CUSTOM: " << request.url().toString().toStdString() << std::endl; |
226 | +#endif |
227 | + return QSharedPointer<click::network::Reply>(new click::network::Reply(networkAccessManagerInstance().sendCustomRequest(request, verb, data), id)); |
228 | } |
229 | + |
230 | |
231 | === modified file 'libclickscope/click/network_access_manager.h' |
232 | --- libclickscope/click/network_access_manager.h 2014-05-20 19:33:41 +0000 |
233 | +++ libclickscope/click/network_access_manager.h 2016-05-06 14:29:14 +0000 |
234 | @@ -51,7 +51,7 @@ |
235 | |
236 | public: |
237 | // A Reply instance takes over ownership of the underlying QNetworkReply. |
238 | - explicit Reply(QNetworkReply* reply); |
239 | + explicit Reply(QNetworkReply* reply, int id = 0); |
240 | Reply(const Reply&) = delete; |
241 | virtual ~Reply(); |
242 | |
243 | @@ -93,6 +93,7 @@ |
244 | virtual QSharedPointer<Reply> head(QNetworkRequest& request); |
245 | virtual QSharedPointer<Reply> post(QNetworkRequest& request, QByteArray& data); |
246 | virtual QSharedPointer<Reply> sendCustomRequest(QNetworkRequest& request, QByteArray& verb, QIODevice *data = 0); |
247 | + static bool languageChanged(); |
248 | }; |
249 | } |
250 | } |
251 | |
252 | === modified file 'libclickscope/click/preview.cpp' |
253 | --- libclickscope/click/preview.cpp 2016-04-01 17:16:05 +0000 |
254 | +++ libclickscope/click/preview.cpp 2016-05-06 14:29:14 +0000 |
255 | @@ -215,7 +215,7 @@ |
256 | } else { |
257 | qWarning() << "unexpected action id " << QString::fromStdString(action_id) |
258 | << " given with download_url" << QString::fromStdString(download_url); |
259 | - return new UninstalledPreview(result, client, depts, manager, ppackage); |
260 | + return new UninstalledPreview(result, metadata, client, depts, manager, ppackage); |
261 | } |
262 | } else if (metadict.count(click::Preview::Actions::CANCEL_PURCHASE_UNINSTALLED) != 0) { |
263 | return new CancelPurchasePreview(result, false); |
264 | @@ -224,18 +224,18 @@ |
265 | } else if (metadict.count(click::Preview::Actions::UNINSTALL_CLICK) != 0) { |
266 | return new UninstallConfirmationPreview(result); |
267 | } else if (metadict.count(click::Preview::Actions::CONFIRM_UNINSTALL) != 0) { |
268 | - return new UninstallingPreview(result, client, manager, ppackage); |
269 | + return new UninstallingPreview(result, metadata, client, manager, ppackage); |
270 | } else if (metadict.count(click::Preview::Actions::CONFIRM_CANCEL_PURCHASE_UNINSTALLED) != 0) { |
271 | - return new CancellingPurchasePreview(result, client, ppackage, manager, false); |
272 | + return new CancellingPurchasePreview(result, metadata, client, ppackage, manager, false); |
273 | } else if (metadict.count(click::Preview::Actions::CONFIRM_CANCEL_PURCHASE_INSTALLED) != 0) { |
274 | - return new CancellingPurchasePreview(result, client, ppackage, manager, true); |
275 | + return new CancellingPurchasePreview(result, metadata, client, ppackage, manager, true); |
276 | } else if (metadict.count(click::Preview::Actions::RATED) != 0) { |
277 | return new InstalledPreview(result, metadata, client, ppackage, depts); |
278 | } else if (metadict.count(click::Preview::Actions::SHOW_UNINSTALLED) != 0) { |
279 | - return new UninstalledPreview(result, client, depts, manager, ppackage); |
280 | + return new UninstalledPreview(result, metadata, client, depts, manager, ppackage); |
281 | } else { |
282 | qWarning() << "preview() called with unexpected metadata. returning uninstalled preview"; |
283 | - return new UninstalledPreview(result, client, depts, manager, ppackage); |
284 | + return new UninstalledPreview(result, metadata, client, depts, manager, ppackage); |
285 | } |
286 | } else { |
287 | // metadata.scope_data() is Null, so we return an appropriate "default" preview: |
288 | @@ -246,7 +246,7 @@ |
289 | if (result["installed"].get_bool() == true) { |
290 | return new InstalledPreview(result, metadata, client, ppackage, depts); |
291 | } else { |
292 | - return new UninstalledPreview(result, client, depts, manager, ppackage); |
293 | + return new UninstalledPreview(result, metadata, client, depts, manager, ppackage); |
294 | } |
295 | } |
296 | |
297 | @@ -410,7 +410,7 @@ |
298 | // to decide whether to show error widgets. see bug LP: #1289541 |
299 | void PreviewStrategy::populateDetails(std::function<void(const click::PackageDetails& details)> details_callback, |
300 | std::function<void(const click::ReviewList&, |
301 | - click::Reviews::Error)> reviews_callback) |
302 | + click::Reviews::Error)> reviews_callback, bool force_cache) |
303 | { |
304 | |
305 | std::string app_name = get_string_maybe_null(result["name"]); |
306 | @@ -429,9 +429,9 @@ |
307 | // I think this should not be required when we switch the click::Index over |
308 | // to using the Qt bridge. With that, the qt dependency becomes an implementation detail |
309 | // and code using it does not need to worry about threading/event loop topics. |
310 | - run_under_qt([this, details_callback, reviews_callback, app_name]() |
311 | + run_under_qt([this, details_callback, reviews_callback, app_name, force_cache]() |
312 | { |
313 | - index_operation = index->get_details(app_name, [this, app_name, details_callback, reviews_callback](PackageDetails details, click::Index::Error error){ |
314 | + index_operation = index->get_details(app_name, [this, app_name, details_callback, reviews_callback, force_cache](PackageDetails details, click::Index::Error error){ |
315 | if(error == click::Index::Error::NoError) { |
316 | qDebug() << "Got details:" << app_name.c_str(); |
317 | details_callback(details); |
318 | @@ -445,8 +445,9 @@ |
319 | details_callback(details); |
320 | } |
321 | reviews_operation = reviews->fetch_reviews(app_name, |
322 | - reviews_callback); |
323 | - }); |
324 | + reviews_callback, |
325 | + force_cache); |
326 | + }, force_cache); |
327 | }); |
328 | } |
329 | } |
330 | @@ -842,6 +843,9 @@ |
331 | |
332 | void InstalledPreview::run(unity::scopes::PreviewReplyProxy const& reply) |
333 | { |
334 | + const bool force_cache = (metadata.internet_connectivity() == scopes::QueryMetadata::ConnectivityStatus::Disconnected); |
335 | + qDebug() << "preview, force_cache=" << force_cache << ", conn status=" << (int)metadata.internet_connectivity(); |
336 | + |
337 | // Check if the user is submitting a rating, so we can submit it. |
338 | Review review; |
339 | review.rating = 0; |
340 | @@ -911,7 +915,7 @@ |
341 | submit_future.get(); |
342 | } |
343 | } |
344 | - getApplicationUri(manifest, [this, reply, manifest, app_name, &review, userid](const std::string& uri) { |
345 | + getApplicationUri(manifest, [this, reply, manifest, app_name, &review, userid, force_cache](const std::string& uri) { |
346 | populateDetails([this, reply, uri, manifest, app_name](const PackageDetails &details){ |
347 | cachedDetails = details; |
348 | store_department(details); |
349 | @@ -954,7 +958,7 @@ |
350 | } |
351 | cachedWidgets.flush(reply); |
352 | reply->finished(); |
353 | - }); |
354 | + }, force_cache); |
355 | }); |
356 | } |
357 | |
358 | @@ -1207,12 +1211,14 @@ |
359 | // class UninstalledPreview |
360 | |
361 | UninstalledPreview::UninstalledPreview(const unity::scopes::Result& result, |
362 | + const unity::scopes::ActionMetadata& metadata, |
363 | const QSharedPointer<click::web::Client>& client, |
364 | const std::shared_ptr<click::DepartmentsDb>& depts, |
365 | const QSharedPointer<Ubuntu::DownloadManager::Manager>& manager, |
366 | const QSharedPointer<pay::Package>& ppackage) |
367 | : PreviewStrategy(result, client, ppackage), |
368 | DepartmentUpdater(depts), |
369 | + metadata(metadata), |
370 | dm(new DownloadManager(client, manager)) |
371 | { |
372 | qDebug() << "Creating new UninstalledPreview for result" << QString::fromStdString(result["name"].get_string()); |
373 | @@ -1224,6 +1230,9 @@ |
374 | |
375 | void UninstalledPreview::run(unity::scopes::PreviewReplyProxy const& reply) |
376 | { |
377 | + const bool force_cache = (metadata.internet_connectivity() == scopes::QueryMetadata::ConnectivityStatus::Disconnected); |
378 | + qDebug() << "preview, force_cache=" << force_cache << ", conn status=" << (int)metadata.internet_connectivity(); |
379 | + |
380 | qDebug() << "in UninstalledPreview::run, about to populate details"; |
381 | populateDetails([this, reply](const PackageDetails &details){ |
382 | store_department(details); |
383 | @@ -1257,7 +1266,7 @@ |
384 | reply->finished(); |
385 | qDebug() << "---------- Finished reply for:" << result["name"].get_string().c_str(); |
386 | }); |
387 | - }); |
388 | + }, force_cache); |
389 | } |
390 | |
391 | scopes::PreviewWidgetList UninstalledPreview::uninstalledActionButtonWidgets(const PackageDetails &details) |
392 | @@ -1310,10 +1319,11 @@ |
393 | |
394 | // TODO: this class should be removed once uninstall() is handled elsewhere. |
395 | UninstallingPreview::UninstallingPreview(const unity::scopes::Result& result, |
396 | + const unity::scopes::ActionMetadata& metadata, |
397 | const QSharedPointer<click::web::Client>& client, |
398 | const QSharedPointer<Ubuntu::DownloadManager::Manager>& manager, |
399 | const QSharedPointer<pay::Package>& ppackage) |
400 | - : UninstalledPreview(result, client, nullptr, manager, ppackage) |
401 | + : UninstalledPreview(result, metadata, client, nullptr, manager, ppackage) |
402 | { |
403 | } |
404 | |
405 | @@ -1353,11 +1363,12 @@ |
406 | // class CancellingPurchasePreview : public UninstallingPreview |
407 | |
408 | CancellingPurchasePreview::CancellingPurchasePreview(const unity::scopes::Result& result, |
409 | + const unity::scopes::ActionMetadata& metadata, |
410 | const QSharedPointer<click::web::Client>& client, |
411 | const QSharedPointer<pay::Package>& ppackage, |
412 | const QSharedPointer<Ubuntu::DownloadManager::Manager>& manager, |
413 | bool installed) |
414 | - : UninstallingPreview(result, client, manager, ppackage), |
415 | + : UninstallingPreview(result, metadata, client, manager, ppackage), |
416 | installed(installed) |
417 | { |
418 | } |
419 | |
420 | === modified file 'libclickscope/click/preview.h' |
421 | --- libclickscope/click/preview.h 2016-03-07 14:10:27 +0000 |
422 | +++ libclickscope/click/preview.h 2016-05-06 14:29:14 +0000 |
423 | @@ -177,7 +177,8 @@ |
424 | protected: |
425 | virtual void populateDetails(std::function<void(const PackageDetails &)> details_callback, |
426 | std::function<void(const click::ReviewList&, |
427 | - click::Reviews::Error)> reviews_callback); |
428 | + click::Reviews::Error)> reviews_callback, |
429 | + bool force_cache = false); |
430 | virtual scopes::PreviewWidgetList headerWidgets(const PackageDetails &details); |
431 | virtual scopes::PreviewWidgetList screenshotsWidgets(const PackageDetails &details); |
432 | virtual scopes::PreviewWidgetList descriptionWidgets(const PackageDetails &details); |
433 | @@ -317,6 +318,7 @@ |
434 | { |
435 | public: |
436 | UninstalledPreview(const unity::scopes::Result& result, |
437 | + const unity::scopes::ActionMetadata& metadata, |
438 | const QSharedPointer<click::web::Client>& client, |
439 | const std::shared_ptr<click::DepartmentsDb>& depts, |
440 | const QSharedPointer<Ubuntu::DownloadManager::Manager>& manager, |
441 | @@ -326,6 +328,7 @@ |
442 | |
443 | void run(unity::scopes::PreviewReplyProxy const& reply) override; |
444 | protected: |
445 | + scopes::ActionMetadata metadata; |
446 | PackageDetails found_details; |
447 | CachedPreviewWidgets cachedWidgets; |
448 | std::string found_object_path; |
449 | @@ -340,6 +343,7 @@ |
450 | { |
451 | public: |
452 | UninstallingPreview(const unity::scopes::Result& result, |
453 | + const unity::scopes::ActionMetadata& metadata, |
454 | const QSharedPointer<click::web::Client>& client, |
455 | const QSharedPointer<Ubuntu::DownloadManager::Manager>& manager, |
456 | const QSharedPointer<pay::Package>& ppackage); |
457 | @@ -357,6 +361,7 @@ |
458 | { |
459 | public: |
460 | CancellingPurchasePreview(const unity::scopes::Result& result, |
461 | + const unity::scopes::ActionMetadata& metadata, |
462 | const QSharedPointer<click::web::Client>& client, |
463 | const QSharedPointer<pay::Package>& ppackage, |
464 | const QSharedPointer<Ubuntu::DownloadManager::Manager>& manager, |
465 | |
466 | === modified file 'libclickscope/click/reviews.cpp' |
467 | --- libclickscope/click/reviews.cpp 2016-04-01 17:16:05 +0000 |
468 | +++ libclickscope/click/reviews.cpp 2016-05-06 14:29:14 +0000 |
469 | @@ -126,13 +126,14 @@ |
470 | } |
471 | |
472 | click::web::Cancellable Reviews::fetch_reviews (const std::string& package_name, |
473 | - std::function<void(ReviewList, Error)> callback) |
474 | + std::function<void(ReviewList, Error)> callback, |
475 | + bool force_cache) |
476 | { |
477 | click::web::CallParams params; |
478 | params.add(click::REVIEWS_QUERY_ARGNAME, package_name.c_str()); |
479 | QSharedPointer<click::web::Response> response = client->call |
480 | (get_base_url() + click::REVIEWS_API_PATH, "GET", false, |
481 | - std::map<std::string, std::string>{}, "", params); |
482 | + std::map<std::string, std::string>{}, "", params, force_cache); |
483 | |
484 | QObject::connect(response.data(), &click::web::Response::finished, |
485 | [=](QString reply) { |
486 | |
487 | === modified file 'libclickscope/click/reviews.h' |
488 | --- libclickscope/click/reviews.h 2015-11-24 18:23:23 +0000 |
489 | +++ libclickscope/click/reviews.h 2016-05-06 14:29:14 +0000 |
490 | @@ -78,7 +78,8 @@ |
491 | virtual ~Reviews(); |
492 | |
493 | virtual click::web::Cancellable fetch_reviews (const std::string& package_name, |
494 | - std::function<void(ReviewList, Error)> callback); |
495 | + std::function<void(ReviewList, Error)> callback, |
496 | + bool force_cache = false); |
497 | click::web::Cancellable submit_review (const Review& review, |
498 | std::function<void(Error)> callback); |
499 | click::web::Cancellable edit_review (const Review& review, |
500 | |
501 | === modified file 'libclickscope/click/webclient.cpp' |
502 | --- libclickscope/click/webclient.cpp 2016-04-01 17:16:05 +0000 |
503 | +++ libclickscope/click/webclient.cpp 2016-05-06 14:29:14 +0000 |
504 | @@ -80,10 +80,11 @@ |
505 | |
506 | QSharedPointer<click::web::Response> click::web::Client::call( |
507 | const std::string& iri, |
508 | - const click::web::CallParams& params) |
509 | + const click::web::CallParams& params, |
510 | + bool force_cache) |
511 | { |
512 | return call(iri, "GET", true, |
513 | - std::map<std::string, std::string>(), "", params); |
514 | + std::map<std::string, std::string>(), "", params, force_cache); |
515 | } |
516 | |
517 | QSharedPointer<click::web::Response> click::web::Client::call( |
518 | @@ -92,7 +93,8 @@ |
519 | bool sign, |
520 | const std::map<std::string, std::string>& headers, |
521 | const std::string& data, |
522 | - const click::web::CallParams& params) |
523 | + const click::web::CallParams& params, |
524 | + bool force_cache) |
525 | { |
526 | QUrl url(iri.c_str()); |
527 | url.setQuery(params.query); |
528 | @@ -104,7 +106,11 @@ |
529 | request->setRawHeader(ACCEPT_LANGUAGE_HEADER.c_str(), |
530 | Configuration().get_accept_languages().c_str()); |
531 | |
532 | - request->setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache); |
533 | + if (force_cache) { |
534 | + qDebug() << "Forcing cache"; |
535 | + } |
536 | + request->setAttribute(QNetworkRequest::CacheLoadControlAttribute, force_cache ? QNetworkRequest::AlwaysCache : QNetworkRequest::PreferCache); |
537 | + request->setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true); |
538 | |
539 | for (const auto& kv : headers) { |
540 | QByteArray header_name(kv.first.c_str(), kv.first.length()); |
541 | |
542 | === modified file 'libclickscope/click/webclient.h' |
543 | --- libclickscope/click/webclient.h 2016-04-01 17:16:05 +0000 |
544 | +++ libclickscope/click/webclient.h 2016-05-06 14:29:14 +0000 |
545 | @@ -117,14 +117,14 @@ |
546 | |
547 | virtual QSharedPointer<Response> call( |
548 | const std::string& iri, |
549 | - const CallParams& params = CallParams()); |
550 | + const CallParams& params = CallParams(), bool force_cache = false); |
551 | virtual QSharedPointer<Response> call( |
552 | const std::string& iri, |
553 | const std::string& method, |
554 | bool sign = true, |
555 | const std::map<std::string, std::string>& headers = std::map<std::string, std::string>(), |
556 | const std::string& data = "", |
557 | - const CallParams& params = CallParams()); |
558 | + const CallParams& params = CallParams(), bool force_cache = false); |
559 | void setCredentialsService(const QSharedPointer<click::CredentialsService>& sso); |
560 | virtual void invalidateCredentials(); |
561 | |
562 | |
563 | === modified file 'libclickscope/tests/mock_webclient.h' |
564 | --- libclickscope/tests/mock_webclient.h 2016-04-01 17:16:05 +0000 |
565 | +++ libclickscope/tests/mock_webclient.h 2016-05-06 14:29:14 +0000 |
566 | @@ -86,7 +86,7 @@ |
567 | const click::web::CallParams& params)); |
568 | QSharedPointer<click::web::Response> call( |
569 | const std::string& iri, |
570 | - const click::web::CallParams& params=click::web::CallParams()) override { |
571 | + const click::web::CallParams& params=click::web::CallParams(), bool = false) override { |
572 | return callImpl(iri, "GET", true, |
573 | std::map<std::string, std::string>(), "", params); |
574 | } |
575 | @@ -96,7 +96,7 @@ |
576 | bool sign = true, |
577 | const std::map<std::string, std::string>& headers = std::map<std::string, std::string>(), |
578 | const std::string& data = "", |
579 | - const click::web::CallParams& params=click::web::CallParams()) override { |
580 | + const click::web::CallParams& params=click::web::CallParams(), bool = false) override { |
581 | return callImpl(iri, method, sign, headers, data, params); |
582 | } |
583 | |
584 | |
585 | === modified file 'libclickscope/tests/test_preview.cpp' |
586 | --- libclickscope/tests/test_preview.cpp 2016-02-24 17:50:03 +0000 |
587 | +++ libclickscope/tests/test_preview.cpp 2016-05-06 14:29:14 +0000 |
588 | @@ -64,7 +64,7 @@ |
589 | FakeIndex() { |
590 | |
591 | } |
592 | - click::web::Cancellable get_details(const std::string& /*package_name*/, std::function<void(click::PackageDetails, Error)> callback) override { |
593 | + click::web::Cancellable get_details(const std::string& /*package_name*/, std::function<void(click::PackageDetails, Error)> callback, bool) override { |
594 | callback(click::PackageDetails(), Error::NetworkError); |
595 | return click::web::Cancellable(); |
596 | } |
597 | @@ -78,7 +78,7 @@ |
598 | |
599 | } |
600 | |
601 | - click::web::Cancellable fetch_reviews(const std::string &/*package_name*/, std::function<void (click::ReviewList, Error)> callback) override { |
602 | + click::web::Cancellable fetch_reviews(const std::string &/*package_name*/, std::function<void (click::ReviewList, Error)> callback, bool) override { |
603 | callback(click::ReviewList(), Error::NoError); |
604 | return click::web::Cancellable(); |
605 | } |
606 | @@ -406,11 +406,12 @@ |
607 | public: |
608 | FakeBaseUninstalledPreview(const std::string& object_path, |
609 | const unity::scopes::Result& result, |
610 | + const unity::scopes::ActionMetadata& metadata, |
611 | const QSharedPointer<click::web::Client>& client, |
612 | const std::shared_ptr<click::DepartmentsDb>& depts, |
613 | const QSharedPointer<Ubuntu::DownloadManager::Manager>& manager, |
614 | const QSharedPointer<pay::Package> pay_package) |
615 | - : click::UninstalledPreview(result, client, depts, manager, pay_package), |
616 | + : click::UninstalledPreview(result, metadata, client, depts, manager, pay_package), |
617 | object_path(object_path) |
618 | { |
619 | } |
620 | @@ -429,11 +430,12 @@ |
621 | MOCK_METHOD1(progressBarWidget, scopes::PreviewWidgetList(const std::string& object_path)); |
622 | FakeUninstalledPreview(const std::string& object_path, |
623 | const unity::scopes::Result& result, |
624 | + const unity::scopes::ActionMetadata& metadata, |
625 | const QSharedPointer<click::web::Client>& client, |
626 | const std::shared_ptr<click::DepartmentsDb>& depts, |
627 | const QSharedPointer<Ubuntu::DownloadManager::Manager>& manager, |
628 | const QSharedPointer<pay::Package> pay_package) |
629 | - : FakeBaseUninstalledPreview(object_path, result, client, depts, manager, pay_package) { |
630 | + : FakeBaseUninstalledPreview(object_path, result, metadata, client, depts, manager, pay_package) { |
631 | } |
632 | }; |
633 | |
634 | @@ -444,7 +446,8 @@ |
635 | |
636 | result["name"] = "fake_app_name"; |
637 | scopes::PreviewWidgetList response; |
638 | - FakeUninstalledPreview preview(fake_object_path, result, client, depts, sdm, pay_package); |
639 | + unity::scopes::ActionMetadata metadata("en_EN", "desktop"); |
640 | + FakeUninstalledPreview preview(fake_object_path, result, metadata, client, depts, sdm, pay_package); |
641 | EXPECT_CALL(preview, progressBarWidget(_)) |
642 | .Times(1) |
643 | .WillOnce(Return(response)); |
644 | @@ -458,7 +461,8 @@ |
645 | |
646 | result["name"] = "fake_app_name"; |
647 | scopes::PreviewWidgetList response; |
648 | - FakeUninstalledPreview preview(fake_object_path, result, client, depts, sdm, pay_package); |
649 | + unity::scopes::ActionMetadata metadata("en_EN", "desktop"); |
650 | + FakeUninstalledPreview preview(fake_object_path, result, metadata, client, depts, sdm, pay_package); |
651 | EXPECT_CALL(preview, uninstalledActionButtonWidgets(_)) |
652 | .Times(1) |
653 | .WillOnce(Return(response)); |
654 | @@ -468,11 +472,12 @@ |
655 | class FakeUninstalledRefundablePreview : FakeBaseUninstalledPreview { |
656 | public: |
657 | FakeUninstalledRefundablePreview(const unity::scopes::Result& result, |
658 | + const unity::scopes::ActionMetadata& metadata, |
659 | const QSharedPointer<click::web::Client>& client, |
660 | const std::shared_ptr<click::DepartmentsDb>& depts, |
661 | const QSharedPointer<Ubuntu::DownloadManager::Manager>& manager, |
662 | const QSharedPointer<pay::Package> pay_package) |
663 | - : FakeBaseUninstalledPreview(std::string{""}, result, client, depts, manager, pay_package){ |
664 | + : FakeBaseUninstalledPreview(std::string{""}, result, metadata, client, depts, manager, pay_package){ |
665 | } |
666 | using click::UninstalledPreview::uninstalledActionButtonWidgets; |
667 | MOCK_METHOD0(isRefundable, bool()); |
668 | @@ -493,7 +498,8 @@ |
669 | result["name"] = "fake_app_name"; |
670 | result["price"] = 2.99; |
671 | result["purchased"] = true; |
672 | - FakeUninstalledRefundablePreview preview(result, client, depts, sdm, pay_package); |
673 | + unity::scopes::ActionMetadata metadata("en_EN", "desktop"); |
674 | + FakeUninstalledRefundablePreview preview(result, metadata, client, depts, sdm, pay_package); |
675 | |
676 | click::PackageDetails pkgdetails; |
677 | EXPECT_CALL(preview, isRefundable()).Times(1) |
678 | @@ -506,7 +512,8 @@ |
679 | result["name"] = "fake_app_name"; |
680 | result["price"] = 2.99; |
681 | result["purchased"] = true; |
682 | - FakeUninstalledRefundablePreview preview(result, client, depts, sdm, pay_package); |
683 | + unity::scopes::ActionMetadata metadata("en_EN", "desktop"); |
684 | + FakeUninstalledRefundablePreview preview(result, metadata, client, depts, sdm, pay_package); |
685 | |
686 | click::PackageDetails pkgdetails; |
687 | EXPECT_CALL(preview, isRefundable()).Times(1) |
688 | |
689 | === modified file 'scope/clickstore/store-query.cpp' |
690 | --- scope/clickstore/store-query.cpp 2016-01-12 10:23:19 +0000 |
691 | +++ scope/clickstore/store-query.cpp 2016-05-06 14:29:14 +0000 |
692 | @@ -46,7 +46,6 @@ |
693 | #include <unity/scopes/Variant.h> |
694 | #include <unity/scopes/VariantBuilder.h> |
695 | |
696 | -#include <iostream> |
697 | #include <iomanip> |
698 | #include<vector> |
699 | #include<set> |
700 | @@ -533,11 +532,14 @@ |
701 | this->finished(searchReply); //FIXME: this shouldn't be needed |
702 | }; |
703 | |
704 | + const bool force_cache = (search_metadata().internet_connectivity() == scopes::QueryMetadata::ConnectivityStatus::Disconnected); |
705 | + qDebug() << "search, force_cache=" << force_cache << ", conn status=" << (int)search_metadata().internet_connectivity(); |
706 | + |
707 | // this is the case when we do bootstrap for the first time, or it failed last time |
708 | if (impl->department_lookup.size() == 0) |
709 | { |
710 | qDebug() << "performing bootstrap request"; |
711 | - impl->search_operation = impl->index.bootstrap([this, search_cb, searchReply, installedPackages](const DepartmentList& deps, const |
712 | + impl->search_operation = impl->index.bootstrap([this, search_cb, searchReply, installedPackages, force_cache](const DepartmentList& deps, const |
713 | HighlightList& highlights, click::Index::Error error, int) { |
714 | if (error == click::Index::Error::NoError) |
715 | { |
716 | @@ -574,10 +576,10 @@ |
717 | { |
718 | qDebug() << "starting search of" << QString::fromStdString(query().query_string()); |
719 | push_departments(searchReply); |
720 | - impl->search_operation = impl->index.search(query().query_string(), query().department_id(), search_cb); |
721 | + impl->search_operation = impl->index.search(query().query_string(), query().department_id(), search_cb, force_cache); |
722 | } |
723 | } |
724 | - }); |
725 | + }, force_cache); |
726 | } |
727 | else |
728 | { |
729 | @@ -589,7 +591,7 @@ |
730 | { |
731 | qDebug() << "starting search of" << QString::fromStdString(query().query_string()); |
732 | push_departments(searchReply); |
733 | - impl->search_operation = impl->index.search(query().query_string(), query().department_id(), search_cb); |
734 | + impl->search_operation = impl->index.search(query().query_string(), query().department_id(), search_cb, force_cache); |
735 | } |
736 | } |
737 | }); |
738 | |
739 | === modified file 'scope/tests/test_helpers.h' |
740 | --- scope/tests/test_helpers.h 2015-12-01 15:39:41 +0000 |
741 | +++ scope/tests/test_helpers.h 2016-05-06 14:29:14 +0000 |
742 | @@ -53,14 +53,15 @@ |
743 | |
744 | } |
745 | |
746 | - click::web::Cancellable search(const std::string &query, const std::string &department, std::function<void (click::Packages, click::Packages)> callback) override |
747 | + click::web::Cancellable search(const std::string &query, const std::string &department, std::function<void (click::Packages, click::Packages)> callback, |
748 | + bool) override |
749 | { |
750 | do_search(query, department, callback); |
751 | callback(packages, recommends); |
752 | return click::web::Cancellable(); |
753 | } |
754 | |
755 | - click::web::Cancellable bootstrap(std::function<void(const click::DepartmentList&, const click::HighlightList&, Error, int)> callback) override |
756 | + click::web::Cancellable bootstrap(std::function<void(const click::DepartmentList&, const click::HighlightList&, Error, int)> callback, bool) override |
757 | { |
758 | callback(bootstrap_departments, bootstrap_highlights, click::Index::Error::NoError, 0); |
759 | return click::web::Cancellable(); |
FAILED: Continuous integration, rev:446 jenkins. qa.ubuntu. com/job/ unity-scope- click-ci/ 738/ jenkins. qa.ubuntu. com/job/ unity-scope- click-wily- amd64-ci/ 142/console jenkins. qa.ubuntu. com/job/ unity-scope- click-wily- armhf-ci/ 138/console
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild: s-jenkins. ubuntu- ci:8080/ job/unity- scope-click- ci/738/ rebuild
http://