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

LF-4625 Readability Refactors on Ensemble controller code #3663

Open
wants to merge 2 commits into
base: integration
Choose a base branch
from

Conversation

kathyavini
Copy link
Collaborator

@kathyavini kathyavini commented Jan 23, 2025

Description

(As mentioned in tech daily Jan 23rd) These readability refactors on the Ensemble portion of the controller code were done as part of the ticket scope of the original controller ticket. The changes are limited to using a constant where there was a hardcoded string, refactoring out a few .reduce() functions for readability, and clarifying a few return statements that were set up misleadingly. A lot of the Ensemble code (probably whole add flow, maybe webhook function as well) is going to be removed in our "remove old sensors code" task, but I wanted to merge the refactors because:

  • if we are ever going to refer to that old code when expanding sensors, I think it should help us understand what was done in the original flow
  • I have been using the changes (actually it might be just the constant 😂) in my subsequent work on Ensemble controllers so it would be useful to have it in

Removing CSV is not going to be part of this ticket; that should happen in the cleanup/removal task.

Jira link: https://lite-farm.atlassian.net/browse/LF-4625

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • Passes test case
  • UI components visually reviewed on desktop view
  • UI components visually reviewed on mobile view
  • Other (please explain)

Checklist:

  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • The precommit and linting ran successfully
  • I have added or updated language tags for text that's part of the UI
  • I have added "MISSING" for all new language tags to languages I don't speak
  • I have added the GNU General Public License to all new files

… for readability

Remove reduce in favour of more readable array methods; encapsulate all three Ensemble methods into one function; define a constant for 'Ensemble Scientific'
…adability

Remove unused returned values from registerOrganizationWebhook; un-nest code run when function does not return early; add comments to make more explicit how bulkSensorClaim response is defined from Ensemble API response
@kathyavini kathyavini self-assigned this Jan 23, 2025
@kathyavini kathyavini requested review from a team as code owners January 23, 2025 19:20
@kathyavini kathyavini requested review from antsgar, SayakaOno and Duncan-Brain and removed request for a team January 23, 2025 19:20
Copy link
Collaborator

@Duncan-Brain Duncan-Brain left a comment

Choose a reason for hiding this comment

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

I am good with this since if you think it will help, we are deleting it all mostly is my understanding though.

reduce() I believe is much faster for large volumes, and small reduce functions are fairly readable (I like (acc, cv) over (previous, current) from other author though ;) But filter + map is also readable if this is for looking back.

await FarmExternalIntegrationsModel.updateWebhookId(farmId, response.data.id);
return { ...response.data, status: response.status };
};
await ensembleAPICall(accessToken, axiosObject, onError, onResponse);
Copy link
Collaborator

@Duncan-Brain Duncan-Brain Jan 24, 2025

Choose a reason for hiding this comment

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

While unused the return statement gave the option to see result of webhook call. Wondering if error message throwing change with return placement too.

Copy link
Collaborator

@SayakaOno SayakaOno left a comment

Choose a reason for hiding this comment

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

Looks good!

I don’t think reduce() is faster for large datasets... I feel like discussions around reduce VS map/forEach often come up, let’s confirm this sometime 😂

@Duncan-Brain
Copy link
Collaborator

@SayakaOno I am more interested in readability before premature optimization more just a personal note on small reduce functions and finding them fairly readable. I also like filter + map.

Not authoritative reading I did lately for

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants