-
Notifications
You must be signed in to change notification settings - Fork 25
Add filtering to get providers function #497
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
base: master
Are you sure you want to change the base?
Add filtering to get providers function #497
Conversation
|
@DarkLord017 : Thank you for contributing. My guess is this PR won't get looked at for a bit because #147 isn't in our GA milestone. Just letting you know to set expectations. |
| private _shuffle<T>(array: T[]): T[] { | ||
| // Fisher-Yates shuffle | ||
| const arr = array.slice() | ||
| for (let i = arr.length - 1; i > 0; i--) { |
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.
I usually write this loop condition like for (let i = arr.length; i-- > 0;)
| return providers | ||
| } | ||
|
|
||
| private _shuffle<T>(array: T[]): T[] { |
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.
this can be static because it doesn't use this.
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.
consider moving it to rand.ts
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.
Okay
| ) | ||
| }) | ||
|
|
||
| return filter.randomize ? this._shuffle(result) : result |
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.
is the order without randomize well-defined?
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.
They are sorted by ids see this in service provider registry contract
for (uint256 i = 1; i <= numProviders && resultIndex < limit; i++) {
if (providers[i].isActive) {
if (currentIndex >= offset && currentIndex < offset + limit) {
providerIds[resultIndex++] = i;
}
currentIndex++;
}
}
and in synapse
if (providerIds.length > 0) {
const ids = providerIds.map((id: bigint) => Number(id))
providerPromises.push(this.getProviders(ids))
}
offset += pageSize
}
// Wait for all provider details to be fetched and flatten the results
const providerBatches = await Promise.all(providerPromises)
return providerBatches.flat()
34901f3 to
c19de80
Compare
Fixes #147
Provider filtering feature:
ProviderFilterOptionsinterface insp-registry/types.tsto specify filtering criteria such astype,location, piece size, IPNI support, service status, price, proving period, and randomization.providerFilteringmethod inSPRegistryServiceto filter providers according to the given options and optionally randomize the output._shuffleutility method to randomize provider lists when requested.)