Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Use the database category value for Elasticsearch model #829

Merged
merged 6 commits into from
Aug 30, 2022

Conversation

obulat
Copy link
Contributor

@obulat obulat commented Jul 29, 2022

Fixes

Fixes #710 by @obulat

Description

On the first implementation of filtering by category, catalog database did not have the category field.

Then, the API implemented a computation of the category. However, because of the order of code computation, the computed value was (anyways) overwritten by the value in the upstream database, even if it was None.

This PR removes the categorize module for category computation because it is done by the catalog.

Testing Instructions

Note: I could not run just init from this branch. The only way I could test this branch is by using the changes to load_sample_data script from #830.

Testing this PR

To test that the code uses category from the database, change sample_image.csv items. You would need to replace the second last item in the rows with either digitized_artwork or illustration. Then, run just init and go to http://localhost:8000/v1/images/?category=digitized_artwork,illustration. You should see two results.

Testing that category computation does not work

You can see that the current code always replaces the computed category (including illustration for .svg items, and default for provider, such as digitized_artwork for clevelandmuseum).

  1. Checkout the main branch.
  2. Change sample_image.csv items. In the first item, we set category to None (by deleting the second from last item in the row) and replace the provider and source with clevelandmuseum. If the code was implemented correctly, the image category would be set to digitized_artwork as the default category for clevelandmuseum. In the second item, set the URL extension to .svg, and delete the categoryvalue. The category for items with svg extension were supposed to be set to illustration. You can simply the first 2 lines in sample_image.csv with the copy below:
0e3315c5-3328-4a99-80ab-567ac32f685f,2021-12-15 20:49:19.976193+00,2021-12-15 20:49:19.976193+00,provider_api,clevelandmuseum,clevelandmuseum,51745822704,https://www.flickr.com/photos/54633257@N04/51745822704,https://live.staticflickr.com/65535/51745822704_ae97226e20_b.jpg,https://live.staticflickr.com/65535/51745822704_ae97226e20_m.jpg,433,1024,97150,by-nc-sa,2.0,mexicofist3,https://www.flickr.com/photos/54633257@N04,my dress is not very short,"{""views"": ""5991"", ""pub_date"": ""1639443671"", ""date_taken"": ""2021-07-20 18:19:25"", ""description"": ""dressed"", ""license_url"": ""https://creativecommons.org/licenses/by-nc-sa/2.0/"", ""raw_license_url"": null}",,f,2021-12-15 20:49:19.976193+00,f,jpg,,0.9989994997498749
b840de61-fb9d-4ec5-9572-8d778875869f,2021-12-15 20:49:19.976193+00,2021-12-15 20:49:19.976193+00,provider_api,flickr,flickr,51745349583,https://www.flickr.com/photos/129684398@N07/51745349583,https://live.staticflickr.com/65535/51745349583_cebf1fa6e0_b.svg,https://live.staticflickr.com/65535/51745349583_cebf1fa6e0_m.jpg,1024,713,171956,by-nc,2.0,clairetresse,https://www.flickr.com/photos/129684398@N07,Barranco de las bodegas,"{""views"": ""4156"", ""pub_date"": ""1639440673"", ""date_taken"": ""2021-10-28 10:54:43"", ""description"": ""Descente dans un des Barranco, descente prudente parce que ça glisse. L’érosion des sols est extrêmement puissante, les reliefs sont sculptés par les forces de la nature telles que le vente les pluies . Descent in one of the Barranco, careful descent because it slips. The erosion of the soil is extremely powerful, the reliefs are sculpted by the forces of nature such as the rains."", ""license_url"": ""https://creativecommons.org/licenses/by-nc/2.0/"", ""raw_license_url"": null}","[{""name"": ""bardenas"", ""provider"": ""flickr""}, {""name"": ""barranco"", ""provider"": ""flickr""}, {""name"": ""desert"", ""provider"": ""flickr""}, {""name"": ""espagne"", ""provider"": ""flickr""}, {""name"": ""glaise"", ""provider"": ""flickr""}, {""name"": ""navarre"", ""provider"": ""flickr""}, {""name"": ""pyrennees"", ""provider"": ""flickr""}, {""name"": ""ravin"", ""provider"": ""flickr""}, {""name"": ""roches"", ""provider"": ""flickr""}, {""name"": ""water"", ""provider"": ""flickr""}]",f,2021-12-15 20:49:19.976193+00,f,jpg,,0.9985583853916387

If you run just init on main with these lines, and search for digitized_artwork items (http://localhost:8000/v1/images/?category=digitized_artwork), you will not get any results.

And if you replaced the last line here:

category = get_category(extension, source)
if "category" in schema:
category = row[schema["category"]]

with
category = row[schema["category"]] or category
you would see that the category falls back to the computed value if the database category is NULL.

Checklist

  • My pull request has a descriptive title (not a vague title like Update 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.

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.

@openverse-bot openverse-bot added ✨ goal: improvement Improvement to an existing user-facing feature 💻 aspect: code Concerns the software code in the repository 🟨 priority: medium Not blocking but should be addressed soon labels Jul 29, 2022
@github-actions
Copy link

github-actions bot commented Jul 29, 2022

API Developer Docs Preview: Ready

https://wordpress.github.io/openverse-api/_preview/829

Please note that GitHub pages takes a little time to deploy newly pushed code, if the links above don't work or you see old versions, wait 5 minutes and try again.

You can check the GitHub pages deployment action list to see the current status of the deployments.

@obulat obulat marked this pull request as ready for review August 1, 2022 09:26
@obulat obulat requested a review from a team as a code owner August 1, 2022 09:26
@obulat obulat requested review from krysal and stacimc August 1, 2022 09:26
@dhruvkb
Copy link
Member

dhruvkb commented Aug 2, 2022

@obulat how does this PR relate to PR #839?

@obulat
Copy link
Contributor Author

obulat commented Aug 3, 2022

@obulat how does this PR relate to PR #839?

It is related only insofar as both steps are run during the data refresh process, and both PRs would simplify and speed it up. However, the big difference is that #839 is blocked because the upstream database needs to be cleaned up before removing the API clean up process, but this PR can be merged as is. The computed category information was mostly unused by the API, and upstream has a lot of the computed category data.

Copy link
Member

@dhruvkb dhruvkb left a comment

Choose a reason for hiding this comment

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

These changes look very valid to me.

@@ -42,7 +42,7 @@ class Image(ImageFileMixin, AbstractMedia):
"""
Inherited fields
================
category: eg. photograph, digitised artwork & illustration
category: eg. photograph, digitized_artwork & illustration
Copy link
Member

Choose a reason for hiding this comment

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

My UK-based spellchecker gets me into a lot of trouble.

@openverse-bot
Copy link
Collaborator

Based on the medium urgency of this PR, the following reviewers are being gently reminded to review this PR:

@krysal
@stacimc
This reminder is being automatically generated due to the urgency configuration.

Excluding weekend1 days, this PR was updated 4 day(s) ago. PRs labelled with medium urgency are expected to be reviewed within 4 weekday(s)2.

@obulat, if this PR is not ready for a review, please draft it to prevent reviewers from getting further unnecessary pings.

Footnotes

  1. Specifically, Saturday and Sunday.

  2. For the purpose of these reminders we treat Monday - Friday as weekdays. Please note that the that generates these reminders runs at midnight UTC on Monday - Friday. This means that depending on your timezone, you may be pinged outside of the expected range.

@obulat obulat merged commit 1f32bb8 into main Aug 30, 2022
@obulat obulat deleted the remove_category_computation branch August 30, 2022 16:30
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
💻 aspect: code Concerns the software code in the repository data normalization ✨ goal: improvement Improvement to an existing user-facing feature 🟨 priority: medium Not blocking but should be addressed soon
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove the code for assigning categories to images
4 participants