-
Notifications
You must be signed in to change notification settings - Fork 23
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?
| * @param filter - Filtering options | ||
| * @returns Filtered list of providers | ||
| */ | ||
| async providerFiltering(filter?: ProviderFilterOptions): Promise<ProviderInfo[]> { |
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 think we want a different name for this method, like filterProviders.
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 result | ||
| } | ||
| } | ||
| /** * Filter providers based on criteria |
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 appears to be missing a newline
| // Fisher-Yates shuffle | ||
| const arr = array.slice() | ||
| for (let i = arr.length - 1; i > 0; i--) { | ||
| const j = Math.floor(Math.random() * (i + 1)) |
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.
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.)