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

Create a mapping of media type to SQL constants #2678

Closed
stacimc opened this issue Jul 19, 2023 · 0 comments · Fixed by #2964
Closed

Create a mapping of media type to SQL constants #2678

stacimc opened this issue Jul 19, 2023 · 0 comments · Fixed by #2964
Labels
💻 aspect: code Concerns the software code in the repository ✨ goal: improvement Improvement to an existing user-facing feature 🟨 priority: medium Not blocking but should be addressed soon

Comments

@stacimc
Copy link
Collaborator

stacimc commented Jul 19, 2023

Current Situation

See comments here and here.

In many of our SQL tasks we have code that looks like this:

# Default variables to correspond to the `image` media type
def create_standardized_media_popularity_function(
    postgres_conn_id,
    media_type=IMAGE,
    function_name=STANDARDIZED_IMAGE_POPULARITY_FUNCTION,
    popularity_constants=IMAGE_POPULARITY_CONSTANTS_VIEW,
):
    # In the function body, hard-coded update if the media type differs
    if media_type == AUDIO:
        popularity_constants = AUDIO_POPULARITY_CONSTANTS_VIEW
        function_name = STANDARDIZED_AUDIO_POPULARITY_FUNCTION

Suggested Improvement

We should define a mapping of media types to each of the constants needed in SQL operations (table and view names, function names, columns, etc). We should then get the values for these constants from the dictionary. Tests should also be updated.

Benefit

Code clean-up, but this was also make it easier to add additional media types in the future.

Additional context

@stacimc stacimc added 🟨 priority: medium Not blocking but should be addressed soon ✨ goal: improvement Improvement to an existing user-facing feature 💻 aspect: code Concerns the software code in the repository labels Jul 19, 2023
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Openverse Backlog Jul 19, 2023
@stacimc stacimc mentioned this issue Sep 2, 2023
8 tasks
@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in Openverse Backlog Sep 12, 2023
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: improvement Improvement to an existing user-facing feature 🟨 priority: medium Not blocking but should be addressed soon
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant