perf(typesense): skip collection check for search operations #898
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What is this?
This PR improves search performance in the Typesense driver by removing an unnecessary collection existence check during search operations. Currently, before executing any search, there's an API call out to the collection's endpoint that verifies if a collection exists, which adds latency that increases with collection size and complexity. By skipping this verification specifically for search operations while maintaining it for indexing, we can significantly improve search response times.
Changes
Code Changes:
src/Engines/TypesenseEngine.php
:getOrCreateCollectionFromModel()
to add early return whenindexOperation
is falsePerformance Improvements:
Demo
Before this change, each search operation required two API calls:
/collections/{name}
- Collection verification/collections/{name}/documents/search
- Actual searchAfter this change, search operations only make the necessary search API call, while index operations maintain all safety checks.
Context
This optimization was prompted by a user's report of latency issues during search operations, particularly noticeable in larger collections. The change aligns with performance best practices by eliminating redundant API calls while maintaining data integrity through appropriate verification during index operations. I opened up an issue on #897 to keep track of the issue and the changes. This PR closes #897.