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

Add skip_cache parameter to bypass similarity search cache in Feed API #2095

Merged
merged 3 commits into from
Oct 21, 2024

Conversation

jayjay-w
Copy link
Contributor

@jayjay-w jayjay-w commented Oct 17, 2024

Description

  • Introduced skip_cache parameter to Feed API, allowing requests to bypass the similarity search cache when set to true.
  • Updated search_for_similar_published_fact_checks in SmoochSearch to support cached and non-cached search logic.
  • Added search_for_similar_published_fact_checks_no_cache method to perform non-cached similarity searches.
  • Modified FeedResource to handle and pass the skip_cache parameter.

References: CV2-2400

How has this been tested?

Ensured all existing tests are still passing

Things to pay attention to during code review

Check if anything was missed

Checklist

  • I have performed a self-review of my own code
  • I have added unit and feature tests, if the PR implements a new feature or otherwise would benefit from additional testing
  • I have added regression tests, if the PR fixes a bug
  • I have added logging, exception reporting, and custom tracing with any additional information required for debugging
  • I considered secure coding practices when writing this code. Any security concerns are noted above.
  • I have commented my code in hard-to-understand areas, if any
  • I have made needed changes to the README
  • My changes generate no new warnings
  • If I added a third party module, I included a rationale for doing so and followed our current guidelines

Comment on lines 60 to 64
if skip_cache
results = Bot::Smooch.search_for_similar_published_fact_checks_no_cache(type, query, feed.team_ids, after, feed_id)
else
results = Bot::Smooch.search_for_similar_published_fact_checks(type, query, feed.team_ids, after, feed_id)
end
Copy link
Contributor

Choose a reason for hiding this comment

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

@jayjay-w as per our conversation, let's move this logic to inside Bot::Smooch.search_for_similar_published_fact_checks - so, this is the method that can receive the skip_cache parameter and then bypass cache if true - please confirm if Rails.cache.fetch can take a force argument that bypasses cache.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So it turns out there's no force option for Rails.cache.fetch, so I changed this to use a conditional if.

- Introduced `skip_cache` parameter to Feed API, allowing requests to bypass the similarity search cache when set to `true`.
- Updated `search_for_similar_published_fact_checks` in `SmoochSearch` to support cached and non-cached search logic.
- Added `search_for_similar_published_fact_checks_no_cache` method to perform non-cached similarity searches.
- Modified `FeedResource` to handle and pass the `skip_cache` parameter.
- Implemented automated test for `skip_cache` functionality to ensure correct behavior.
- Updated logging for better traceability of cache usage in similarity searches.
@jayjay-w jayjay-w force-pushed the CV2-5400-add-skip-cache-param branch from 5a4d4f5 to 1e7eb7a Compare October 18, 2024 14:40
@jayjay-w jayjay-w force-pushed the CV2-5400-add-skip-cache-param branch from 1e7eb7a to 7c0240d Compare October 18, 2024 19:14
@jayjay-w jayjay-w marked this pull request as ready for review October 18, 2024 20:10
Copy link
Contributor

@caiosba caiosba left a comment

Choose a reason for hiding this comment

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

Please make sure tests are fixed and code is still fully covered.

app/models/concerns/smooch_search.rb Outdated Show resolved Hide resolved
app/models/concerns/smooch_search.rb Outdated Show resolved Hide resolved
Copy link
Contributor

@caiosba caiosba 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 addressing all comments from the previous PR review!

@jayjay-w jayjay-w merged commit bc3941b into develop Oct 21, 2024
11 checks passed
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