Skip to content

[Enhancement] Prevent videos in cache from refreshing too often #5635

@Fijxu

Description

@Fijxu

I recently noticed that the Invidious video cache that is stored in the database to prevent fetching the video again in again from Innertube limited /player endpoint makes Invidious re-fetch the video if it has been clicked a user within those 10 minutes.

(Time.utc - video.updated > 10.minutes) ||

I think this value for the cache was in place to keep the video information updated in case there was any changes back when the Innertube /player endpoint wasn't limited, but since we are now rate limited, this value would be better to sit at 6 hours (which is the current expiration time of the video stream since the video was requested) or we can calculate it from the expire query parameter in videoplayback requests. Or we can just remove this check and rely on:

def delete_expired
request = <<-SQL
DELETE FROM nonces *
WHERE expire < now()
SQL
PG_DB.exec(request)
end

with it's job to remove the expired (or ones that are going to expire) videos from cache:

begin
Invidious::Database::Videos.delete_expired
Invidious::Database::Nonces.delete_expired
rescue DB::Error
failed = true
end
# Retry earlier than scheduled on DB error
if failed
LOGGER.info("jobs: ClearExpiredItems failed. Retrying in 10 minutes.")
sleep 10.minutes
else
LOGGER.info("jobs: ClearExpiredItems done.")
sleep 1.hour
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions