Skip to content

Commit 3dd2014

Browse files
authored
Ensured first indexing pass runs if a source has never been indexed before (#581)
1 parent 993c57f commit 3dd2014

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

lib/pinchflat/slow_indexing/slow_indexing_helpers.ex

+2-1
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,9 @@ defmodule Pinchflat.SlowIndexing.SlowIndexingHelpers do
231231
# The download archive isn't useful for playlists (since those are ordered arbitrarily)
232232
# and we don't want to use it if the indexing was forced by the user. In other words,
233233
# only create an archive for channels that are being indexed as part of their regular
234-
# indexing schedule
234+
# indexing schedule. The first indexing pass should also not create an archive.
235235
defp build_download_archive_options(%Source{collection_type: :playlist}, _was_forced), do: []
236+
defp build_download_archive_options(%Source{last_indexed_at: nil}, _was_forced), do: []
236237
defp build_download_archive_options(_source, true), do: []
237238

238239
defp build_download_archive_options(source, _was_forced) do

test/pinchflat/slow_indexing/slow_indexing_helpers_test.exs

+19-2
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,9 @@ defmodule Pinchflat.SlowIndexing.SlowIndexingHelpersTest do
475475
end
476476

477477
describe "index_and_enqueue_download_for_media_items when testing the download archive" do
478-
test "a download archive is used if the source is a channel", %{source: source} do
478+
test "a download archive is used if the source is a channel that has been indexed before" do
479+
source = source_fixture(%{collection_type: :channel, last_indexed_at: now()})
480+
479481
expect(YtDlpRunnerMock, :run, fn _url, :get_media_attributes_for_collection, opts, _ot, _addl_opts ->
480482
assert :break_on_existing in opts
481483
assert Keyword.has_key?(opts, :download_archive)
@@ -499,6 +501,19 @@ defmodule Pinchflat.SlowIndexing.SlowIndexingHelpersTest do
499501
SlowIndexingHelpers.index_and_enqueue_download_for_media_items(source)
500502
end
501503

504+
test "a download archive is not used if the source has never been indexed before" do
505+
source = source_fixture(%{collection_type: :channel, last_indexed_at: nil})
506+
507+
expect(YtDlpRunnerMock, :run, fn _url, :get_media_attributes_for_collection, opts, _ot, _addl_opts ->
508+
refute :break_on_existing in opts
509+
refute Keyword.has_key?(opts, :download_archive)
510+
511+
{:ok, source_attributes_return_fixture()}
512+
end)
513+
514+
SlowIndexingHelpers.index_and_enqueue_download_for_media_items(source)
515+
end
516+
502517
test "a download archive is not used if the index has been forced to run" do
503518
source = source_fixture(%{collection_type: :channel})
504519

@@ -512,7 +527,9 @@ defmodule Pinchflat.SlowIndexing.SlowIndexingHelpersTest do
512527
SlowIndexingHelpers.index_and_enqueue_download_for_media_items(source, was_forced: true)
513528
end
514529

515-
test "the download archive is formatted correctly and contains the right video", %{source: source} do
530+
test "the download archive is formatted correctly and contains the right video" do
531+
source = source_fixture(%{collection_type: :channel, last_indexed_at: now()})
532+
516533
media_items =
517534
1..21
518535
|> Enum.map(fn n ->

0 commit comments

Comments
 (0)