Skip to content
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

farmer|rpc: Introduce get_harvesters_summary RPC endpoint #11245

Merged

Conversation

xdustinface
Copy link
Contributor

This will be later used by the GUI as part of the GUI improvements to support large farms.

@xdustinface xdustinface force-pushed the pr-farmer-get-harvesters-count-only branch from e53dedd to b2838c8 Compare April 21, 2022 11:34
@xdustinface xdustinface changed the title farmer|rpc: Add optional counts_only parameter to get_harvesters farmer|rpc: Introduce get_harvesters_summary RPC endpoint Apr 21, 2022
@xdustinface xdustinface force-pushed the pr-farmer-get-harvesters-count-only branch from b2838c8 to a1b737e Compare April 22, 2022 11:09
@xdustinface xdustinface marked this pull request as ready for review April 22, 2022 11:09
Copy link
Contributor

@altendky altendky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some thoughts about optional (maybe later) adjustments.

"failed_to_open_filenames": self._invalid,
"no_key_filenames": self._keys_missing,
"duplicates": self._duplicates,
"plots": get_list_or_len(list(self._plots.values()), counts_only),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe drop the helper function?

Suggested change
"plots": get_list_or_len(list(self._plots.values()), counts_only),
"plots": len(self._plots) if counts_only else list(self._plots.values())),

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look at the tests, imagine how it looks if i write it explicitly everywhere and tell me again if you really want to drop it :)

@@ -68,3 +71,7 @@ def prompt_yes_no(prompt: str = "(y/n) ") -> bool:
return True
elif ch == "n":
return False


def get_list_or_len(list_in: Sequence[object], length: bool) -> Union[int, Sequence[object]]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Collection is sufficient here to get the len() ability. Also, that should be a TypeVar to indicate that the output type is the same as the input type. Also, also, with typing_extensions.Literal for True and False we could skip the Union and use overloads to express which thing will come out based on the length parameter.

Suggested change
def get_list_or_len(list_in: Sequence[object], length: bool) -> Union[int, Sequence[object]]:
def get_list_or_len(list_in: Collection[object], length: bool) -> Union[int, Collection[object]]:

Or we could delete this as use the ternary directly when needed. :]

@@ -102,8 +103,9 @@ async def test_get_routes(harvester_farmer_environment):
await validate_get_routes(harvester_rpc_client, harvester_rpc_api)


@pytest.mark.parametrize("endpoint", ["get_harvesters", "get_harvesters_summary"])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be FarmerRpcApi.get_harvesters instead of strings and getattr() below. (or whatever the proper class is) Then you endpoint(instance, parameters) to call it and pass the instance into self.

@xdustinface xdustinface added the ready_to_merge Submitter and reviewers think this is ready label Apr 28, 2022
@wjblanke wjblanke merged commit b693aeb into Chia-Network:main Apr 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready_to_merge Submitter and reviewers think this is ready
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants