From 3dd20141e07b15dd10749cae24997d4e75b8733d Mon Sep 17 00:00:00 2001 From: Kieran Date: Tue, 21 Jan 2025 11:55:27 -0800 Subject: [PATCH] Ensured first indexing pass runs if a source has never been indexed before (#581) --- .../slow_indexing/slow_indexing_helpers.ex | 3 ++- .../slow_indexing_helpers_test.exs | 21 +++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/pinchflat/slow_indexing/slow_indexing_helpers.ex b/lib/pinchflat/slow_indexing/slow_indexing_helpers.ex index 433af5a..ed70007 100644 --- a/lib/pinchflat/slow_indexing/slow_indexing_helpers.ex +++ b/lib/pinchflat/slow_indexing/slow_indexing_helpers.ex @@ -231,8 +231,9 @@ defmodule Pinchflat.SlowIndexing.SlowIndexingHelpers do # The download archive isn't useful for playlists (since those are ordered arbitrarily) # and we don't want to use it if the indexing was forced by the user. In other words, # only create an archive for channels that are being indexed as part of their regular - # indexing schedule + # indexing schedule. The first indexing pass should also not create an archive. defp build_download_archive_options(%Source{collection_type: :playlist}, _was_forced), do: [] + defp build_download_archive_options(%Source{last_indexed_at: nil}, _was_forced), do: [] defp build_download_archive_options(_source, true), do: [] defp build_download_archive_options(source, _was_forced) do diff --git a/test/pinchflat/slow_indexing/slow_indexing_helpers_test.exs b/test/pinchflat/slow_indexing/slow_indexing_helpers_test.exs index f1368c2..2ef57ef 100644 --- a/test/pinchflat/slow_indexing/slow_indexing_helpers_test.exs +++ b/test/pinchflat/slow_indexing/slow_indexing_helpers_test.exs @@ -475,7 +475,9 @@ defmodule Pinchflat.SlowIndexing.SlowIndexingHelpersTest do end describe "index_and_enqueue_download_for_media_items when testing the download archive" do - test "a download archive is used if the source is a channel", %{source: source} do + test "a download archive is used if the source is a channel that has been indexed before" do + source = source_fixture(%{collection_type: :channel, last_indexed_at: now()}) + expect(YtDlpRunnerMock, :run, fn _url, :get_media_attributes_for_collection, opts, _ot, _addl_opts -> assert :break_on_existing in opts assert Keyword.has_key?(opts, :download_archive) @@ -499,6 +501,19 @@ defmodule Pinchflat.SlowIndexing.SlowIndexingHelpersTest do SlowIndexingHelpers.index_and_enqueue_download_for_media_items(source) end + test "a download archive is not used if the source has never been indexed before" do + source = source_fixture(%{collection_type: :channel, last_indexed_at: nil}) + + expect(YtDlpRunnerMock, :run, fn _url, :get_media_attributes_for_collection, opts, _ot, _addl_opts -> + refute :break_on_existing in opts + refute Keyword.has_key?(opts, :download_archive) + + {:ok, source_attributes_return_fixture()} + end) + + SlowIndexingHelpers.index_and_enqueue_download_for_media_items(source) + end + test "a download archive is not used if the index has been forced to run" do source = source_fixture(%{collection_type: :channel}) @@ -512,7 +527,9 @@ defmodule Pinchflat.SlowIndexing.SlowIndexingHelpersTest do SlowIndexingHelpers.index_and_enqueue_download_for_media_items(source, was_forced: true) end - test "the download archive is formatted correctly and contains the right video", %{source: source} do + test "the download archive is formatted correctly and contains the right video" do + source = source_fixture(%{collection_type: :channel, last_indexed_at: now()}) + media_items = 1..21 |> Enum.map(fn n ->