from django.core.cache import cache

from videos.models import Video, Series

CACHE_TTL = 300


def video_lists(request):
    movie_list = cache.get("video_lists_movie_list")
    if movie_list is None:
        movie_list = list(
            Video.objects.filter(video_type=Video.VideoType.MOVIE).only("id", "title")
        )
        cache.set("video_lists_movie_list", movie_list, CACHE_TTL)

    series_list = cache.get("video_lists_series_list")
    if series_list is None:
        series_list = list(Series.objects.all().only("id", "name"))
        cache.set("video_lists_series_list", series_list, CACHE_TTL)

    return {
        "movie_list": movie_list,
        "series_list": series_list,
    }
