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

Ensure we don't send unnecessary API requests to NLU #455

Merged
merged 4 commits into from
May 18, 2023
Merged

Conversation

dkotter
Copy link
Collaborator

@dkotter dkotter commented May 10, 2023

Description of the Change

As detailed in #415, there's a request on each page load (admin or front-end) to the NLU API to check to see if authentication is valid. These requests are unnecessary, leading to potential performance issues but more importantly, extra API usage.

This PR fixes that by refactoring the can_register method that all Providers use. For all other Providers besides NLU, we've removed the can_register method and instead rely on the parent can_register method.

For NLU, the can_register method now calls the is_configured method, which calls the parent is_configured method (matching what other providers do) but also checks the existing classifai_configured option to retain backwards compatibility. These changes fix the extra API requests, remove duplicate code and helps make things a little more consistent between Providers.

Closes #415

How to test the Change

Ensure all Providers still work if configured properly and don't work if not configured properly

Changelog Entry

Changed - Standardize on how we determine if a Provider is configured
Fixed - Avoid extra API requests to the NLU endpoint

Credits

Props @dkotter, @benlk

Checklist:

  • I agree to follow this project's Code of Conduct.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests pass.

…d to be a wrapper for the new is_configured method. For all existing providers that had the same can_register check, remove that method from the child class so they will rely on the parent method
…n other providers. Update the can_register method of NLU to match more closely to other providers as well
@dkotter dkotter self-assigned this May 10, 2023
@dkotter dkotter requested review from a team and jeffpaul as code owners May 10, 2023 20:02
@dkotter dkotter changed the title Fix/415 Ensure we don't send unnecessary API requests to NLU May 10, 2023
@dkotter dkotter added this to the 2.2.0 milestone May 10, 2023
iamdharmesh
iamdharmesh previously approved these changes May 18, 2023
Copy link
Member

@iamdharmesh iamdharmesh left a comment

Choose a reason for hiding this comment

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

Thanks for working on this and saving lots of requests @dkotter. LGTM. 🚀

Thanks

includes/Classifai/Providers/Watson/NLU.php Outdated Show resolved Hide resolved
@dkotter dkotter merged commit 7a8d8cb into develop May 18, 2023
@dkotter dkotter deleted the fix/415 branch May 18, 2023 17:04
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.

Ensure we don't send unnecessary requests to the Watson API
2 participants