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

Fix dynamically excluded providers caching #3381

Merged
merged 5 commits into from
Nov 23, 2023

Conversation

obulat
Copy link
Contributor

@obulat obulat commented Nov 21, 2023

Fixes

Fixes #3380 by @obulat

Description

This PR saves a list of provider_identifiers for the dynamically-excluded providers to the redis cache, instead of saving the QuerySet.
It also adds two unit tests for the specific functions, but there are also several other tests that test dynamically excluded providers using both cache and the ContentProvider model saved in the database.

Testing Instructions

Run the app, go to http://localhost:50280/admin, select one of the ContentProvider models and check its "Hide Content" property.
Screenshot 2023-11-21 at 5 22 01 PM

Execute a search (http://localhost:50280/v1/images). Check Redis value for :1:filtered_providers (I used the RedisInsights GUI):

Screenshot 2023-11-21 at 5 23 35 PM

Also, check that on main, if you set "Hide content" to true for one of the providers, the value saved in Redis should look like the one in the related issue instead of a list of filtered providers.

Checklist

  • My pull request has a descriptive title (not a vague title likeUpdate index.md).
  • My pull request targets the default branch of the repository (main) or a parent feature branch.
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added or updated tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no visible errors.
  • I ran the DAG documentation generator (if applicable).

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

@github-actions github-actions bot added the 🧱 stack: api Related to the Django API label Nov 21, 2023
@openverse-bot openverse-bot added 🟨 priority: medium Not blocking but should be addressed soon 🛠 goal: fix Bug fix 💻 aspect: code Concerns the software code in the repository labels Nov 21, 2023
@obulat obulat marked this pull request as ready for review November 21, 2023 14:26
@obulat obulat requested a review from a team as a code owner November 21, 2023 14:26
Copy link
Collaborator

@AetherUnbound AetherUnbound left a comment

Choose a reason for hiding this comment

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

Excellent find, and thank you for also improving the tests and documentation!

Copy link
Collaborator

@sarayourfriend sarayourfriend left a comment

Choose a reason for hiding this comment

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

LGTM!

api/api/controllers/search_controller.py Outdated Show resolved Hide resolved
Copy link
Member

@krysal krysal left a comment

Choose a reason for hiding this comment

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

Well seen! LGTM!

@@ -21,7 +21,7 @@
def excluded_providers_cache():
cache_key = "filtered_providers"
Copy link
Member

Choose a reason for hiding this comment

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

This could be replaced with the new FILTERED_PROVIDERS_CACHE_KEY constant from api.controllers.search_controller.

Comment on lines 13 to 17
def excluded_providers_cache():
cache_key = "filtered_providers"
excluded_provider = "excluded_provider"
cache_value = [{"provider_identifier": excluded_provider}]
cache_value = [excluded_provider]
cache.set(cache_key, cache_value, timeout=1)
Copy link
Member

Choose a reason for hiding this comment

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

And the same here!

api/api/controllers/search_controller.py Outdated Show resolved Hide resolved
@obulat obulat force-pushed the fix/dynamically_excluded_providers branch from 415c74b to 0ecd3e0 Compare November 23, 2023 03:58
@obulat obulat merged commit f37a0cd into main Nov 23, 2023
43 checks passed
@obulat obulat deleted the fix/dynamically_excluded_providers branch November 23, 2023 04:14
Copy link

sentry-io bot commented Nov 27, 2023

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

  • ‼️ TypeError: string indices must be integers, not 'str' /v1/audio/{identifier}/related/ View Issue

Did you find this useful? React with a 👍 or 👎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💻 aspect: code Concerns the software code in the repository 🛠 goal: fix Bug fix 🟨 priority: medium Not blocking but should be addressed soon 🧱 stack: api Related to the Django API
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Dynamically filtered providers cache is set incorrectly
5 participants