speed up loading
This commit is contained in:
parent
eb46aaa3b5
commit
7380c65eff
4 changed files with 16 additions and 7 deletions
|
@ -13,12 +13,21 @@ export const usePrices = () => {
|
|||
const [prices, setPrices] = useState(COUNTRIES);
|
||||
useEffect(() => {
|
||||
const fetchAll = async () => {
|
||||
for (const [index, country] of COUNTRIES.entries()) {
|
||||
for (let index = 0; index < prices.length; index += 2) {
|
||||
// intentionally blocking execution
|
||||
// to resolve sequentially.
|
||||
// It should prevent DOS and triggering captcha
|
||||
const found = await bookPriceFor(country);
|
||||
prices[index] = found;
|
||||
if (index + 1 < prices.length) {
|
||||
const [first, second] = await Promise.all([
|
||||
bookPriceFor(prices[index]),
|
||||
bookPriceFor(prices[index + 1]),
|
||||
]);
|
||||
prices[index] = first;
|
||||
prices[index + 1] = second;
|
||||
} else {
|
||||
prices[index] = await bookPriceFor(prices[index]);
|
||||
}
|
||||
|
||||
sortPrices(prices);
|
||||
setPrices([...prices]);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "Kobo Price",
|
||||
"description": "Find lowest book price on kobo.com",
|
||||
"version": "1.2.1",
|
||||
"version": "1.2.3",
|
||||
"manifest_version": 3,
|
||||
"content_scripts": [
|
||||
{
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue