Skip to content

Commit

Permalink
Merge pull request #173 from ar-io/PE-6491-arns-emitter-pagination
Browse files Browse the repository at this point in the history
fix(PE-6491): arns emitter pagination
  • Loading branch information
atticusofsparta authored Jul 25, 2024
2 parents ec36ee0 + b6f2157 commit ab9fad1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ const gateways = await io.getGateways();
"failedConsecutiveEpochs": 0,
"passedEpochCount": 30,
"submittedEpochCount": 30,
"totalEpochParticipationCount": 31,
"totalEpochCount": 31,
"totalEpochsPrescribedCount": 31
},
"status": "joined",
Expand Down Expand Up @@ -364,7 +364,7 @@ const gateway = await io.getGateway({
"failedConsecutiveEpochs": 0,
"passedEpochCount": 30,
"submittedEpochCount": 30,
"totalEpochParticipationCount": 31,
"totalEpochCount": 31,
"totalEpochsPrescribedCount": 31
},
"status": "joined",
Expand Down Expand Up @@ -412,7 +412,7 @@ Available `sortBy` options are any of the keys on the gateway object, e.g. `oper
"failedConsecutiveEpochs": 0,
"passedEpochCount": 30,
"submittedEpochCount": 30,
"totalEpochParticipationCount": 31,
"totalEpochCount": 31,
"totalEpochsPrescribedCount": 31
},
"status": "joined",
Expand Down
2 changes: 1 addition & 1 deletion src/contract-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export type GatewayStats = {
failedConsecutiveEpochs: number;
passedEpochCount: number;
submittedEpochCount: number;
totalEpochParticipationCount: number;
totalEpochCount: number;
totalEpochsPrescribedCount: number;
};

Expand Down
2 changes: 1 addition & 1 deletion src/io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ export type AoEpochData = {
export type AoGatewayStats = {
passedConsecutiveEpochs: number;
failedConsecutiveEpochs: number;
totalEpochParticipationCount: number;
totalEpochCount: number;
passedEpochCount: number;
failedEpochCount: number;
observedEpochCount: number;
Expand Down
14 changes: 11 additions & 3 deletions src/utils/processes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,13 @@ export class ArNSEventEmitter extends EventEmitter {
this.logger = logger;
}

async fetchProcessesOwnedByWallet({ address }: { address: WalletAddress }) {
async fetchProcessesOwnedByWallet({
address,
pageSize,
}: {
address: WalletAddress;
pageSize?: number;
}) {
const uniqueContractProcessIds: Record<
string,
{
Expand All @@ -126,7 +132,7 @@ export class ArNSEventEmitter extends EventEmitter {

await timeout(
this.timeoutMs,
fetchAllArNSRecords({ contract: this.contract, emitter: this }),
fetchAllArNSRecords({ contract: this.contract, emitter: this, pageSize }),
)
.catch((e) => {
this.emit('error', `Error getting ArNS records: ${e}`);
Expand Down Expand Up @@ -201,17 +207,19 @@ export const fetchAllArNSRecords = async ({
}),
emitter,
logger = Logger.default,
pageSize = 50_000,
}: {
contract?: AoIORead;
emitter?: EventEmitter;
logger?: ILogger;
pageSize?: number;
}): Promise<Record<string, AoArNSNameData>> => {
let cursor: string | undefined;
const startTimestamp = Date.now();
const records: Record<string, AoArNSNameData> = {};
do {
const pageResult = await contract
.getArNSRecords({ cursor })
.getArNSRecords({ cursor, limit: pageSize })
.catch((e: any) => {

Check warning on line 223 in src/utils/processes.ts

View workflow job for this annotation

GitHub Actions / build / build (18.x, lint)

Unexpected any. Specify a different type

Check warning on line 223 in src/utils/processes.ts

View workflow job for this annotation

GitHub Actions / build (18.x, lint)

Unexpected any. Specify a different type

Check warning on line 223 in src/utils/processes.ts

View workflow job for this annotation

GitHub Actions / build / build (20.x, lint)

Unexpected any. Specify a different type

Check warning on line 223 in src/utils/processes.ts

View workflow job for this annotation

GitHub Actions / build (20.x, lint)

Unexpected any. Specify a different type
logger?.error(`Error getting ArNS records`, {
message: e?.message,
Expand Down

0 comments on commit ab9fad1

Please sign in to comment.