Skip to content

Commit

Permalink
Retrieve all map data at once (#4469)
Browse files Browse the repository at this point in the history
* Retrieve all data at once

* de-list results

* remove console log

---------

Co-authored-by: kflemin <[email protected]>
  • Loading branch information
haneslinger and kflemin authored Jan 12, 2024
1 parent 4a60eb2 commit 5c10968
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions seed/static/seed/js/controllers/inventory_map_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,24 @@ angular.module('BE.seed.controller.inventory_map', []).controller('inventory_map
};

const chunk = 250;
const fetchRecords = (fn, page = 1) => fn(page, chunk, undefined, undefined).then((data) => {
$scope.progress = {
current: data.pagination.end,
total: data.pagination.total,
percent: Math.round((data.pagination.end / data.pagination.total) * 100)
};
if (data.pagination.has_next) {
return fetchRecords(fn, page + 1).then((newData) => data.results.concat(newData));
}
return data.results;
});
const fetchRecords = async (fn) => {
pagination = await fn(1, chunk, undefined, undefined).then(data => data.pagination);

$scope.progress = {current: 0, total: pagination.total, percent:0};

page_numbers = [...Array(pagination.num_pages).keys()]
page_promises = page_numbers.map(page => {
return fn(page, chunk, undefined, undefined).then(data => {
num_data = data.pagination.end - data.pagination.start + 1;
$scope.progress.current += num_data;
$scope.progress.percent += Math.round((num_data / data.pagination.total) * 100)
return data.results
})
})

return Promise.all(page_promises).then(pages => [].concat(...pages))
}


$scope.progress = {};
const loadingModal = $uibModal.open({
Expand Down

0 comments on commit 5c10968

Please sign in to comment.