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);
|
const [prices, setPrices] = useState(COUNTRIES);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchAll = async () => {
|
const fetchAll = async () => {
|
||||||
for (const [index, country] of COUNTRIES.entries()) {
|
for (let index = 0; index < prices.length; index += 2) {
|
||||||
// intentionally blocking execution
|
// intentionally blocking execution
|
||||||
// to resolve sequentially.
|
// to resolve sequentially.
|
||||||
// It should prevent DOS and triggering captcha
|
// It should prevent DOS and triggering captcha
|
||||||
const found = await bookPriceFor(country);
|
if (index + 1 < prices.length) {
|
||||||
prices[index] = found;
|
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);
|
sortPrices(prices);
|
||||||
setPrices([...prices]);
|
setPrices([...prices]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "Kobo Price",
|
"name": "Kobo Price",
|
||||||
"description": "Find lowest book price on kobo.com",
|
"description": "Find lowest book price on kobo.com",
|
||||||
"version": "1.2.1",
|
"version": "1.2.3",
|
||||||
"manifest_version": 3,
|
"manifest_version": 3,
|
||||||
"content_scripts": [
|
"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