Skip to content

Commit

Permalink
Update app.js
Browse files Browse the repository at this point in the history
  • Loading branch information
manustars authored Oct 7, 2024
1 parent 23a94fb commit 6dc1f8a
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ async function fetchAllMiningRigs() {
let totalPages = 1; // Inizializza a 1 per entrare nel ciclo

while (currentPage < totalPages) {
console.log(`Fetching rigs from page ${currentPage} with size 250`);
console.log(`Fetching rigs from page ${currentPage + 1} with size 250`); // Aggiornato a currentPage + 1 per una migliore leggibilità

const rawResponse = await nhClient.getMiningRigs(currentPage, 250);
const data = rawResponse.data;
Expand All @@ -133,6 +133,12 @@ async function fetchAllMiningRigs() {
if (data && data.miningRigs) {
allMiningRigs = allMiningRigs.concat(data.miningRigs);
console.log(`Retrieved ${data.miningRigs.length} rigs from page ${currentPage + 1}`);

// MODIFICA: Verifica se il numero di rig è inferiore a 250 per l'ultima pagina
if (data.miningRigs.length < 250) {
console.log("Last page retrieved with less than 250 rigs, ending pagination.");
totalPages = currentPage + 1; // Imposta totalPages per terminare il ciclo dopo questa pagina
}
} else {
console.warn(`No mining rigs found on page ${currentPage + 1}`);
}
Expand All @@ -142,9 +148,10 @@ async function fetchAllMiningRigs() {
totalPages = data.pagination.totalPageCount;
console.log(`Total pages: ${totalPages}`);
} else {
console.error(`Total page count not found in response for page ${currentPage}`);
console.error(`Total page count not found in response for page ${currentPage + 1}`);
break; // Esci dal ciclo se non possiamo determinare il numero di pagine
}

currentPage++; // Incrementa per richiedere la pagina successiva
}

Expand All @@ -157,7 +164,6 @@ async function fetchAllMiningRigs() {




async function refreshMetrics() {
minerStatuses.reset()
devicesStatuses.reset()
Expand Down

0 comments on commit 6dc1f8a

Please sign in to comment.