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

[Bugfix] Ensure a full indexing pass always runs if the source has never been indexed before #581

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/pinchflat/slow_indexing/slow_indexing_helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 19 additions & 2 deletions test/pinchflat/slow_indexing/slow_indexing_helpers_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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})

Expand All @@ -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 ->
Expand Down
Loading