Skip to content

Commit 8572f42

Browse files
author
Omar Baradei
committed
fix(availability-sync): simplify unreachable season guard
1 parent c7c1a4b commit 8572f42

2 files changed

Lines changed: 20 additions & 28 deletions

File tree

server/lib/availabilitySync.test.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -798,9 +798,6 @@ describe('AvailabilitySync', () => {
798798
});
799799

800800
it('should not delete seasons when the Jellyfin fetch fails with a non-404 error (e.g. server unreachable)', async () => {
801-
// Mirror of the Plex outage regression test (seerr-team/seerr#1729) for
802-
// the Jellyfin/Emby path, since this change applies the same fallback
803-
// contract to mediaExistsInJellyfin.
804801
configureJellyfin();
805802
configureSonarr([{ syncEnabled: true }]);
806803

@@ -824,15 +821,12 @@ describe('AvailabilitySync', () => {
824821
}
825822
await mediaRepository.save(media);
826823

827-
// Jellyfin is unreachable: item/season fetches reject with a connection
828-
// error (NOT a 404/500). The media genuinely still exists in Jellyfin.
829824
getItemDataImpl = async () => {
830825
throw new Error('connect ECONNREFUSED 127.0.0.1:8096');
831826
};
832827
getSeasonsImpl = async () => {
833828
throw new Error('connect ECONNREFUSED 127.0.0.1:8096');
834829
};
835-
// TMDB reports all three seasons as having episodes...
836830
getTvShowImpl = async () =>
837831
fakeTmdbShow(
838832
1412,
@@ -845,7 +839,6 @@ describe('AvailabilitySync', () => {
845839
season_number: n,
846840
}))
847841
);
848-
// ...and Sonarr does not track the series, so it cannot vouch for them either.
849842
getSeriesByIdImpl = async () => {
850843
throw new Error('404');
851844
};
@@ -974,11 +967,6 @@ describe('AvailabilitySync', () => {
974967

975968
describe('TV season availability - Plex', () => {
976969
it('should not delete seasons when the Plex season fetch fails with a non-404 error (e.g. server unreachable)', async () => {
977-
// Regression test for seerr-team/seerr#1729: when Plex is briefly
978-
// unreachable during an availability sync, the show is correctly kept
979-
// ("Preventing removal"), but every season used to be marked DELETED
980-
// because the empty Plex season map was treated as "confirmed absent".
981-
// A connection error must NOT delete seasons we simply could not verify.
982970
configurePlex();
983971
configureSonarr([{ syncEnabled: true }]);
984972

@@ -1002,15 +990,12 @@ describe('AvailabilitySync', () => {
1002990
}
1003991
await mediaRepository.save(media);
1004992

1005-
// Plex is unreachable: metadata fetches reject with a connection error
1006-
// (NOT a 404). The media genuinely still exists in Plex.
1007993
getMetadataImpl = async () => {
1008994
throw new Error('connect ECONNREFUSED 127.0.0.1:32400');
1009995
};
1010996
getChildrenMetadataImpl = async () => {
1011997
throw new Error('connect ECONNREFUSED 127.0.0.1:32400');
1012998
};
1013-
// TMDB reports all three seasons as having episodes...
1014999
getTvShowImpl = async () =>
10151000
fakeTmdbShow(
10161001
1434,
@@ -1023,7 +1008,6 @@ describe('AvailabilitySync', () => {
10231008
season_number: n,
10241009
}))
10251010
);
1026-
// ...and Sonarr does not track the series, so it cannot vouch for them either.
10271011
getSeriesByIdImpl = async () => {
10281012
throw new Error('404');
10291013
};

server/lib/availabilitySync.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -938,9 +938,6 @@ class AvailabilitySync {
938938
}
939939

940940
// Here we check each season in plex for availability.
941-
// If the API returned an error other than a 404 we could not verify the
942-
// seasons, so we assume the previously-available ones still exist instead
943-
// of deleting media we simply failed to reach (mirrors the show-level guard).
944941
if (media.mediaType === 'tv') {
945942
const seasonsMap: Map<number, boolean> = new Map();
946943

@@ -951,10 +948,15 @@ class AvailabilitySync {
951948
MediaStatus.PARTIALLY_AVAILABLE
952949
);
953950

951+
if (preventSeasonSearch) {
952+
filteredSeasons.forEach((season) =>
953+
seasonsMap.set(season.seasonNumber, true)
954+
);
955+
return { existsInPlex, seasonsMap };
956+
}
957+
954958
for (const season of filteredSeasons) {
955-
const seasonExists = preventSeasonSearch
956-
? true
957-
: await this.seasonExistsInPlex(media, season, is4k);
959+
const seasonExists = await this.seasonExistsInPlex(media, season, is4k);
958960

959961
if (seasonExists) {
960962
seasonsMap.set(season.seasonNumber, true);
@@ -1072,9 +1074,6 @@ class AvailabilitySync {
10721074
}
10731075

10741076
// Here we check each season in jellyfin for availability.
1075-
// If the API returned an error other than a 404 we could not verify the
1076-
// seasons, so we assume the previously-available ones still exist instead
1077-
// of deleting media we simply failed to reach (mirrors the show-level guard).
10781077
if (media.mediaType === 'tv') {
10791078
const seasonsMap: Map<number, boolean> = new Map();
10801079

@@ -1085,10 +1084,19 @@ class AvailabilitySync {
10851084
MediaStatus.PARTIALLY_AVAILABLE
10861085
);
10871086

1087+
if (preventSeasonSearch) {
1088+
filteredSeasons.forEach((season) =>
1089+
seasonsMap.set(season.seasonNumber, true)
1090+
);
1091+
return { existsInJellyfin, seasonsMap };
1092+
}
1093+
10881094
for (const season of filteredSeasons) {
1089-
const seasonExists = preventSeasonSearch
1090-
? true
1091-
: await this.seasonExistsInJellyfin(media, season, is4k);
1095+
const seasonExists = await this.seasonExistsInJellyfin(
1096+
media,
1097+
season,
1098+
is4k
1099+
);
10921100

10931101
if (seasonExists) {
10941102
seasonsMap.set(season.seasonNumber, true);

0 commit comments

Comments
 (0)