Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[offline] Cache inspector reports sequentially, not in parallel #5204

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
- Reduce database queries on shortlist page.
- Provide ResultSet fallback translation in lookup.
- Mark non-Open311 updates as processed by daemon. #4552
- Inspector/planned offline report caching now fetches URLs sequentially, not in parallel.
- Changes:
- Switch to OpenStreetMap for reverse geocoding. #4444
- Convert all uploaded images to JPEGs.
Expand Down
20 changes: 12 additions & 8 deletions web/cobrands/fixmystreet/offline.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,12 @@ fixmystreet.cachet = (function(){
imagesToGet.push(img.src);
imagesToGet.push(img.src.replace('.jpeg', '.fp.jpeg'));
});
var imagePromises = imagesToGet.map(function(url) {
return cacheURL(url);
});
return Promise.all(imagePromises).finally(function() {
// Fetch URLs sequentially rather than in parallel
dracos marked this conversation as resolved.
Show resolved Hide resolved
return imagesToGet.reduce(function(p, url) {
return p.then(function() {
return cacheURL(url);
});
}, Promise.resolve()).finally(function() {
fixmystreet.offlineBanner.progress();
fixmystreet.offlineData.add(item.url, item.lastupdate);
});
Expand All @@ -259,10 +261,12 @@ fixmystreet.cachet = (function(){
// This fetches the HTML and any img elements in that HTML
function cacheReports(items) {
fixmystreet.offlineBanner.startProgress(items.length);
var promises = items.map(function(item) {
return cacheReport(item);
});
return Promise.all(promises);
// We want to cache these one at a time to avoid hammering the server
return items.reduce(function(p, item) {
return p.then(function() {
return cacheReport(item);
});
}, Promise.resolve());
}

return {
Expand Down
Loading