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 a refresh param to /api/v1/videos/:id #4441

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

iBicha
Copy link
Contributor

@iBicha iBicha commented Feb 20, 2024

I found myself needing to fetch video info without caring about the freshness of the details.

Use cases are many, but includes casting from YouTube app (Lounge) iBicha/playlet#276
When user adds a video to the queue, only the video id(s) are sent, so we'd need to make a request to be able to display the video queue.

It would be nice to have an API endpoint (perhaps in v2) where the caller can indicate the details and/or accuracy is not needed, so in that case, older cached videos in the DB are fine, and also, there would be no need to hit the next endpoint. So fetching would need a single request when calling fetch_video

But until then, I thought adding a refresh arg to to the endpoint would be already an improvement and should save processing time and bandwidth.

PS: I haven't tested this (yet)

@iBicha iBicha requested a review from a team as a code owner February 20, 2024 00:39
@iBicha iBicha requested review from unixfox and removed request for a team February 20, 2024 00:39
@iBicha
Copy link
Contributor Author

iBicha commented Feb 20, 2024

Huh I can see this being abused to take down instances by asking to refresh continuously and exhaust the resources.

I don't see how this is possible. The default arg value for refresh in get_video is true, so it was always asking for a fresh video before this PR. This only adds a chance to ask for a less fresh video

@unixfox
Copy link
Member

unixfox commented Feb 20, 2024

I have removed my comment, I thought it was the reverse, asking to always refresh but I guess that's already the case? I thought invidious would refresh only if the cache for the video is older than 10 minutes or something: https://github.com/iv-org/invidious/blob/master/src/invidious/videos.cr#L366

@iBicha
Copy link
Contributor Author

iBicha commented Feb 20, 2024

@unixfox I'm looking again at

def get_video(id, refresh = true, region = nil, force_refresh = false)
and is it me, or does the get_video function not use the region parameter at all? It looks to me that if the region is provided, it is guaranteed to not return any db hit, and instead do a fetch always. On top of that, if the region is specified, the fetched video is not added to the DB. I don't see the fetch_video function use the region in any meaningful way.

@iBicha
Copy link
Contributor Author

iBicha commented Feb 21, 2024

This is now tested and works well iBicha/playlet#300
Saves a lot of unnecessary fetching when older data is fine

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.

None yet

3 participants