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 ADRF and make the thumbnail view async #3020

Merged
merged 7 commits into from
Nov 22, 2023

Conversation

sarayourfriend
Copy link
Collaborator

@sarayourfriend sarayourfriend commented Sep 13, 2023

Fixes

First step of #2789 by @sarayourfriend

Description

This is the first step to convert the image proxy route to async. It converts the overall view to async. I've split this into a separate PR because (a) it is complex enough on its own and (b) converting the actual image_proxy.get function is blocked on sharing the aiohttp client session (for which I'll have another PR up later today, it's already finished I just forgot to push it last night 🤦).

So this PR only converts the view side of things to async. It does this by abstracting the thumbnails route in a slightly different way than it was before, which allows the audio and image views to ignore most of the safe-sync-in-async compatibility issues. To make that interplay a little easier, I decided to refactor image_proxy.get to use two MRO objects for the input, rather than the one-by-one parameter definitions. Now that I'm writing this, I'm realising that I could have avoided the changes to image_proxy.get itself by creating a new response definition for get_image_proxy_media_info and then using asdict to spread that into image_proxy.get. If y'all want me to make that change, I think it's a fine one to simplify the overall PR. On the other hand, I think the new API is also a bit cleaner, if potentially too abstract. Let me know what y'all think because I'm two minds about it.

Testing Instructions

Checkout the PR and run just build web to get the new dependencies. Also keep in mind that this PR depends on #3011.

Run just api/up and make various search requests, thumbnail, and related requests. Generally: exercise the image and audio media views and their various routes. Everything should essentially work as it did before. The existing API integration tests should also continue to work, along will all unit tests. This change should be generally totally transparent and not result in any observable differences on the consumer side, which is why I didn't add any new tests for this: the existing tests already cover the media view and should continue to work without changes. The only tests I changed were to use pook a little more fluidly and to accommodate the changes to the image_proxy.get function's interface.

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.
  • [N/A] 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.

@sarayourfriend sarayourfriend requested a review from a team as a code owner September 13, 2023 01:23
@sarayourfriend sarayourfriend requested review from krysal and obulat and removed request for a team September 13, 2023 01:23
@github-actions github-actions bot added the 🧱 stack: api Related to the Django API label Sep 13, 2023
@openverse-bot openverse-bot added the 🚦 status: awaiting triage Has not been triaged & therefore, not ready for work label Sep 13, 2023
@sarayourfriend sarayourfriend marked this pull request as draft September 18, 2023 05:31
@obulat obulat added 🟧 priority: high Stalls work on the project or its dependents 💻 aspect: code Concerns the software code in the repository 🧰 goal: internal improvement Improvement that benefits maintainers, not users and removed 🚦 status: awaiting triage Has not been triaged & therefore, not ready for work labels Sep 19, 2023
@sarayourfriend sarayourfriend mentioned this pull request Nov 2, 2023
2 tasks
@sarayourfriend sarayourfriend force-pushed the add/async-image-proxy-route branch from 66c95b6 to dc44ee8 Compare November 3, 2023 00:22
Base automatically changed from add/asgi to main November 8, 2023 22:23
@sarayourfriend sarayourfriend force-pushed the add/async-image-proxy-route branch from dc44ee8 to f9c66bf Compare November 16, 2023 19:19
@sarayourfriend sarayourfriend marked this pull request as ready for review November 16, 2023 19:19
Comment on lines -41 to -42
django-split-settings = "*"
psycopg = "~=3.1"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Just moving things into alphabetical order here. The only meaningful change is to add adrf at the top.

is_full_size: bool = False,
is_compressed: bool = True,
media_info: ImageProxyMediaInfo,
proxy_config: ImageProxyConfig = ImageProxyConfig(),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This might be a bad name, maybe "image proxy request config"?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yea I think request_proxy_config for the variable itself might be better 🤔

This does not convert the `image_proxy.get` to async to avoid making this initial PR more complicated than it needs to be, and to avoid being blocked on the aiohttp client session sharing which we will want to have in before we convert the image proxy to use aiohttp.
@sarayourfriend sarayourfriend force-pushed the add/async-image-proxy-route branch from 6d61fd4 to 8897c78 Compare November 20, 2023 06:07
@openverse-bot
Copy link
Collaborator

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

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

Excluding weekend1 days, this PR was ready for review 2 day(s) ago. PRs labelled with high urgency are expected to be reviewed within 2 weekday(s)2.

@sarayourfriend, 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 operation 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.

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.

LGTM! All endpoints seem to be working normally. I did notice a lack of static files in my local server, but it could just be my setup so approving.

image

@sarayourfriend were you able to receive static files? I did a complete rebuild of my images and the static files were not being served.

@sarayourfriend
Copy link
Collaborator Author

I did notice a lack of static files in my local server, but it could just be my setup

I also had this and also assumed it was my local. Clearly a bad assumption from me, apologies. I'll have a fix up soon.

@sarayourfriend
Copy link
Collaborator Author

@dhruvkb Can you run just build web and try again? I've done that locally and the static files are working. Only thing I can think is that maybe one of the dependency changes caused a side-effect?

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.

This looks good! I'm able to build and run it locally, and it appropriately serves the static files for me on localhost:50270 🚀

is_full_size: bool = False,
is_compressed: bool = True,
media_info: ImageProxyMediaInfo,
proxy_config: ImageProxyConfig = ImageProxyConfig(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yea I think request_proxy_config for the variable itself might be better 🤔

Comment on lines +285 to +291
thumbnail_action = action(
detail=True,
url_path="thumb",
url_name="thumb",
serializer_class=media_serializers.MediaThumbnailRequestSerializer,
throttle_classes=[AnonThumbnailRateThrottle, OAuth2IdThumbnailRateThrottle],
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice!

@sarayourfriend
Copy link
Collaborator Author

@AetherUnbound I updated the dataclass names to simplify them and make the request config role clearer.

@sarayourfriend sarayourfriend merged commit b91cdc3 into main Nov 22, 2023
43 checks passed
@sarayourfriend sarayourfriend deleted the add/async-image-proxy-route branch November 22, 2023 00:47
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: internal improvement Improvement that benefits maintainers, not users 🟧 priority: high Stalls work on the project or its dependents 🧱 stack: api Related to the Django API
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

5 participants