-
Notifications
You must be signed in to change notification settings - Fork 54
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
Feature Request: Fallback to default WP search if/when Algolia usage limit reached/exceeded (search operations) #358
Comments
Couple quick thoughts/questions.
I'm seeing In regards to the instantsearch, I think we'd also want to hook in to So one callback on both hooks, that somehow checks on current limits/caps, and returns true or false based on that. |
I'm thinking this should probably be checked when using either "Use Algolia with the native WordPress search template" or "Use Algolia with Instantsearch.js" as both will rely on a search operation from Algolia to complete the request (with the "Do not use Algolia" behavior as the momentary fallback to avoid Algolia while the limits have been exceeded.) Yeah, I trust you know the best hooks to use better than myself so that seems like a fair assessment of things. Also, I only suggested WP cron for checking the usage API as that would help meter out the API calls to keep it reasonable (hourly? daily? somewhere in-between?) while also allowing that check to happen in the background without slowing down any particular request (that check then saving the status of it having met the limit/error or not [or saved as the actual usage value to prep for potentially showing the usage amount in the dashboard at some point while then having errors effectively be considered as 100% usage] as setting or transient [probably setting/option to avoid the complexity/issues of caching/optimization/etc. plugins that like to clear out transient data more often than not] which those 2 hooks then check against to then determine if it should continue as normal or use the fallback WP-based search). In comparison, checking during the search request would likely hit the Usage API way more often (likely more than what's needed) and would slow down the search results from being shown every time (which, again, seems excessive.) Other approaches can be considered, but using WP cron seemed to make some sense for this. |
Word. I hadn't started mentally scoping out the status check aspect, just the "we need to use WP native only" aspects. Yes, we're both thinking the exact same scenarios for the settings, just worded slightly differently. Going to leave the enhancement issue open for any further consideration or anyone wanting to pick it up. |
I discussed this with @tw2113 and I'm just adding some thoughts/comments:
|
Ah, I didn't see that Premium tier notice on the Usage API. That being said... running
Meanwhile, it simply returned:
when the usage went over the monthly limit on a different app ID using effectively that same curl command. So, I'm wondering if they're just not enforcing that premium tier limitation on the Usage API yet (or if it's just limited to specific methods until Premium which unlocks everything...?) and it could potentially be used in the meantime (it's kinda surprising to see this be returned on a free tier setup given that Premium tier messaging, but it seems to be returning some data on multiple free apps using that method.) Also, if any of these API endpoints (or similar; it could probably even just try to perform a search request and see if it gets an error instead of search results rather trying to use the Usage API which might become more limited in the future based on that wording in their documentation) are free to use, it seems like it might be able to just check for whether it says the application is blocked or not as it appears to simply shut off any/all access to that app ID once over the limit when it comes to checking to see if it should gracefully fall back to other search methods until it stops returning that API result (rather than needing to pull & display the specific usage statistics [which could still come after the check if it's returning the |
Is your feature request related to a problem? Please describe.
Currently, people using an Algolia plan that has a limit on usage (be it a free plan or a spending limit on a paid plan) might find their site search simply breaks once the limit is exceeded without any notice or anything. It just shows the search page without any results when this happens (until the usage is reset for another month, etc.) Then needing the site admin to manually turn off Algolia while the limit has been reached to at least have a working search and then manually turn Algolia back on once it's able to be used again.
Describe the solution you'd like
It appears https://www.algolia.com/doc/rest-api/usage/ could potentially be utilized by this plugin to occasionally check for the current search operation usage (possibly using
total_used_search_capacity
or similar?) to see if the Algolia application is indeed able to work or not.Even if pulling individual stats is a bit much (could be nice to surface the usage percentage in the WP dashboard, but that could be a follow-up refinement), it looks like even checking for usage stats via the API of an app that's gone beyond the limit can/will return:
{"status":401,"message":"The application is blocked"}
for the very basic check of whether it should be working or not to decide if it should use the fallback search.For a simple example, it might be nice to check daily/hourly via WP's cron for the Algolia app's usage and then if it returned "The application is blocked" or similar (denoting that trying to perform a search won't work) it could/should automatically switch to simply showing the default WordPress-based search (effectively temporarily use the "Do not use Algolia" option this plugin has until it becomes available again.)
As an aside, Algolia already sends out email notifications when this happens so I don't think this plugin also needs to send an email when this threshold is crossed or anything.
I could see this offered as a feature that's seamless & doesn't need a setting (why allow search to be broken; it kinda just makes sense to at least serve up some form of search results when this happens.)
In summary, the basic idea is to have this plugin periodically check for the Algolia app's usage in the background and if it reached the limit or otherwise gives an error it should then just hand off the search results page to WP's default search and disable trying to offer autocomplete (if enabled) to then have it resume normal functionality once the usage API is no longer reporting the limit having been met or similar error. *Extra bonus would then be to surface the current usage within the site admin so they're more aware of if/when this might occur (while this part could certainly be done separately after this, isn't anywhere near as important as the fallback search aspect, and might also need to check to see what date the monthly usage renews on for that app to then check against... but it could be helpful to people while this is looking at utilizing the Usage API.)
Describe alternatives you've considered
Of course, increasing payment would be the quick & easy fix, but that can be prohibitive for those with spending limits needing to be adhered to and it'd be ideal to have Algolia be used when it can while the site's search doesn't break (fallback to WP search) when Algolia can't be used.
I suppose different fallbacks could be considered, but just having WP's built-in search handle it from seems like the cleanest way to go. Also, different methods for checking for usage could be considered, but checking the usage API seems to be the most relevant.
Additional context
I do want to mention that this probably isn't a candidate for a feature behind the Pro version since it's regarding sites needing to keep costs low while working properly so the ones that need it are likely only able to use the free version of this plugin.
The text was updated successfully, but these errors were encountered: