-
Notifications
You must be signed in to change notification settings - Fork 84
improve(cli): accurate live progress for sync-accounts #171
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -8,12 +8,13 @@ export class AccountSynchronizer extends Synchronizer<IAccount> { | |||||||||||||
| private accountCollection?: Collection<IAccount>; | ||||||||||||||
| private contractAccounts: string[] = []; | ||||||||||||||
| private tokenContracts: string[] = []; | ||||||||||||||
| private totalScopes: number = 0; | ||||||||||||||
| private processedScopes: number = 0; | ||||||||||||||
| private totalScopesToProcess: number = 0; | ||||||||||||||
| private completedContracts: number = 0; | ||||||||||||||
| private totalContracts: number = 0; | ||||||||||||||
| private currentContractIndex: number = 0; | ||||||||||||||
| private currentContract: string = ''; | ||||||||||||||
| private currentScope: string = ''; | ||||||||||||||
| private currentContractScopes: number = 0; // holder scopes processed in the current contract | ||||||||||||||
| private totalScopesProcessed: number = 0; // holder scopes processed across all contracts | ||||||||||||||
| private contractFilter?: string; | ||||||||||||||
|
|
||||||||||||||
| constructor(chain: string, contractFilter?: string) { | ||||||||||||||
|
|
@@ -109,6 +110,7 @@ export class AccountSynchronizer extends Synchronizer<IAccount> { | |||||||||||||
| const contract = this.tokenContracts[i]; | ||||||||||||||
| this.currentContract = contract; | ||||||||||||||
| this.currentContractIndex = i; | ||||||||||||||
| this.currentContractScopes = 0; | ||||||||||||||
| console.log(`[DEBUG] Starting contract ${i + 1}/${this.tokenContracts.length}: ${contract}`); | ||||||||||||||
|
|
||||||||||||||
| let lowerBound: string = ''; | ||||||||||||||
|
|
@@ -143,12 +145,14 @@ export class AccountSynchronizer extends Synchronizer<IAccount> { | |||||||||||||
| } catch (e: any) { | ||||||||||||||
| console.log(`Failed to check balance ${row.scope}@${contract} - ${e.message}`); | ||||||||||||||
| } | ||||||||||||||
| this.currentContractScopes++; | ||||||||||||||
| this.totalScopesProcessed++; | ||||||||||||||
| } | ||||||||||||||
| lowerBound = scopes.more; | ||||||||||||||
| } while (lowerBound !== ''); | ||||||||||||||
|
|
||||||||||||||
| // Mark this contract as processed | ||||||||||||||
| this.processedScopes = i + 1; | ||||||||||||||
| this.completedContracts = i + 1; | ||||||||||||||
| console.log(`[DEBUG] Completed contract ${i + 1}/${this.tokenContracts.length}: ${contract}`); | ||||||||||||||
| } | ||||||||||||||
| console.log(`[DEBUG] All contracts processed`); | ||||||||||||||
|
|
@@ -169,7 +173,7 @@ export class AccountSynchronizer extends Synchronizer<IAccount> { | |||||||||||||
|
|
||||||||||||||
| await this.scanABIs(); | ||||||||||||||
| console.log(`Number of validated token contracts: ${this.tokenContracts.length}`); | ||||||||||||||
| this.totalScopesToProcess = this.tokenContracts.length; | ||||||||||||||
| this.totalContracts = this.tokenContracts.length; | ||||||||||||||
|
|
||||||||||||||
| await this.setupMongo(); | ||||||||||||||
|
|
||||||||||||||
|
|
@@ -184,17 +188,24 @@ export class AccountSynchronizer extends Synchronizer<IAccount> { | |||||||||||||
| } | ||||||||||||||
| return; | ||||||||||||||
| } | ||||||||||||||
| const progressPercent = this.totalScopesToProcess > 0 ? ((this.processedScopes / this.totalScopesToProcess) * 100).toFixed(2) : '0.00'; | ||||||||||||||
|
|
||||||||||||||
| let statusMessage = ''; | ||||||||||||||
| if (this.processedScopes >= this.totalScopesToProcess) { | ||||||||||||||
| // Percentage is driven by completed contracts (the only total known up front). | ||||||||||||||
| // The holder/balance counters below move continuously so a long single-contract | ||||||||||||||
| // sync no longer looks stuck at 0%. | ||||||||||||||
| const progressPercent = this.totalContracts > 0 ? ((this.completedContracts / this.totalContracts) * 100).toFixed(1) : '0.0'; | ||||||||||||||
|
|
||||||||||||||
| let statusMessage: string; | ||||||||||||||
| if (this.completedContracts >= this.totalContracts) { | ||||||||||||||
| statusMessage = 'finalizing database writes...'; | ||||||||||||||
|
Comment on lines
+197
to
199
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If
Suggested change
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Applied in 74f1cce — guarded with |
||||||||||||||
| } else if (this.currentContract) { | ||||||||||||||
| // currentContractIndex is 0-based and set when a contract starts, so +1 reflects the contract in progress | ||||||||||||||
| const contractPos = Math.min(this.currentContractIndex + 1, this.totalContracts); | ||||||||||||||
| statusMessage = `contract ${contractPos}/${this.totalContracts} ${this.currentContract} (${this.currentContractScopes} holders) - current: ${this.currentScope || '...'}`; | ||||||||||||||
| } else { | ||||||||||||||
| statusMessage = this.currentContract ? `${this.currentScope}@${this.currentContract}` : 'initializing...'; | ||||||||||||||
| statusMessage = 'initializing...'; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| const timestamp = new Date().toISOString().split('T')[1].split('.')[0]; // HH:MM:SS format | ||||||||||||||
| console.log(`[${timestamp}] Progress: ${this.processedScopes}/${this.totalScopesToProcess} (${progressPercent}%) - ${statusMessage} - ${this.totalItems} accounts`); | ||||||||||||||
| console.log(`[${timestamp}] ${progressPercent}% | holders scanned: ${this.totalScopesProcessed} | balances: ${this.totalItems} | ${statusMessage}`); | ||||||||||||||
| }, 1000); | ||||||||||||||
|
|
||||||||||||||
| try { | ||||||||||||||
|
|
||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When transitioning to a new contract,
this.currentScopeis not reset. As a result, the progress log will display the last processed scope from the previous contract as thecurrentscope for the new contract until the first scope of the new contract is successfully fetched. Resettingthis.currentScopeto an empty string at the start of each contract avoids this stale/misleading status message.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Applied in 74f1cce — reset
this.currentScope = ''at the start of each contract.