Report a failed podcast search without ending the music search
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
678c7b8211
commit
2ea3f7b337
7 files changed
+119
-31
No files matched your search
+45
-21
@@ -282,7 +282,13 @@ impl Federation {
|
||||
}
|
||||
|
||||
/// The `federation.podcast` events of a search for `user_id`, numbered
|
||||
/// after the music events (see [`podcast_events`]).
|
||||
/// after the music events (see [`podcast_events`]), and the
|
||||
/// `podcast_discovery` state for `search.completed`.
|
||||
///
|
||||
/// Never fails: when the hits cannot be prepared for the account (a
|
||||
/// database error) they are dropped and the state is `failed`, so the
|
||||
/// music results stand and the browser can say the podcast search
|
||||
/// failed.
|
||||
pub async fn podcast_search_events(
|
||||
&self,
|
||||
search_id: &str,
|
||||
@@ -290,28 +296,46 @@ impl Federation {
|
||||
user_id: i64,
|
||||
music: &MusicSearch,
|
||||
podcasts: PodcastSearch,
|
||||
) -> Result<Vec<SearchEvent>> {
|
||||
) -> (&'static str, Vec<SearchEvent>) {
|
||||
let state = podcasts.state();
|
||||
let PodcastSearch::Found(hits) = podcasts else {
|
||||
return Ok(Vec::new());
|
||||
return (state, Vec::new());
|
||||
};
|
||||
let pool = self.pool().await?;
|
||||
let first_sequence = music.events.len() as u64 + 1;
|
||||
let events = podcast_events(
|
||||
&pool,
|
||||
user_id,
|
||||
search_id,
|
||||
query.trim(),
|
||||
&music.items,
|
||||
first_sequence,
|
||||
hits,
|
||||
)
|
||||
.await?;
|
||||
tracing::info!(
|
||||
search_id,
|
||||
podcasts = events.len(),
|
||||
"public podcast hits ready"
|
||||
);
|
||||
Ok(events)
|
||||
if hits.is_empty() {
|
||||
return (state, Vec::new());
|
||||
}
|
||||
let events = async {
|
||||
let pool = self.pool().await?;
|
||||
let first_sequence = music.events.len() as u64 + 1;
|
||||
podcast_events(
|
||||
&pool,
|
||||
user_id,
|
||||
search_id,
|
||||
query.trim(),
|
||||
&music.items,
|
||||
first_sequence,
|
||||
hits,
|
||||
)
|
||||
.await
|
||||
};
|
||||
match events.await {
|
||||
Ok(events) => {
|
||||
tracing::info!(
|
||||
search_id,
|
||||
podcasts = events.len(),
|
||||
"public podcast hits ready"
|
||||
);
|
||||
(state, events)
|
||||
}
|
||||
Err(error) => {
|
||||
// Only the error: never the query or the hits.
|
||||
tracing::warn!(
|
||||
search_id,
|
||||
"public podcast hits could not be prepared: {error:#}"
|
||||
);
|
||||
("failed", Vec::new())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -465,6 +465,7 @@ translations! {
|
||||
player_podcast_request_failed: "Request failed", "Запрос не выполнен";
|
||||
player_podcast_found_title: "Podcasts", "Подкасты";
|
||||
player_podcast_type: "Podcast", "Подкаст";
|
||||
player_podcast_found_failed: "The podcast search did not answer this time; music results are complete.", "Поиск подкастов сейчас не ответил; результаты по музыке полные.";
|
||||
player_podcast_found_subscribed: "Already subscribed", "Уже подписан";
|
||||
player_podcast_found_open: "Open", "Открыть";
|
||||
player_podcast_found_subscribing: "Subscribing…", "Подписываемся…";
|
||||
|
||||
+4
-4
@@ -7507,11 +7507,11 @@ async fn federation_search_events_handler(
|
||||
let podcasts = podcasts
|
||||
.await
|
||||
.unwrap_or(crate::federation::client::PodcastSearch::Failed);
|
||||
let podcast_discovery = podcasts.state();
|
||||
let podcast_events = federation
|
||||
// A podcast search or ranking failure only drops the
|
||||
// podcast hits: `search.completed` reports it.
|
||||
let (podcast_discovery, podcast_events) = federation
|
||||
.podcast_search_events(&body_search_id, &q, user_id, &music, podcasts)
|
||||
.await
|
||||
.map_err(|err| cot::Error::internal(err.to_string()))?;
|
||||
.await;
|
||||
for event in &podcast_events {
|
||||
last_sequence = event.sequence;
|
||||
yield search_event_frame(event)?;
|
||||
|
||||
@@ -367,6 +367,40 @@ mod tests {
|
||||
assert_eq!(http_url(None), None);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn podcast_hits_that_cannot_be_prepared_are_reported_as_failed() {
|
||||
use crate::federation::client::{MusicSearch, PodcastSearch};
|
||||
// The federation handle of a unit test has no database: ranking the
|
||||
// hits for the account fails. The search still completes.
|
||||
let federation = crate::federation::handle();
|
||||
let music = MusicSearch {
|
||||
events: Vec::new(),
|
||||
items: vec![music("Night Radio Theme")],
|
||||
};
|
||||
let (state, events) = federation
|
||||
.podcast_search_events(
|
||||
"search",
|
||||
"night radio",
|
||||
1,
|
||||
&music,
|
||||
PodcastSearch::Found(vec![hit("a.xml", "Night Radio")]),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(state, "failed");
|
||||
assert!(events.is_empty());
|
||||
for (search, expected) in [
|
||||
(PodcastSearch::Found(Vec::new()), "running"),
|
||||
(PodcastSearch::Off, "off"),
|
||||
(PodcastSearch::Failed, "failed"),
|
||||
] {
|
||||
let (state, events) = federation
|
||||
.podcast_search_events("search", "night radio", 1, &music, search)
|
||||
.await;
|
||||
assert_eq!(state, expected);
|
||||
assert!(events.is_empty());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_preview_lists_seasons_and_the_newest_episodes() {
|
||||
let xml = r#"<?xml version="1.0"?>
|
||||
|
||||
@@ -4353,7 +4353,7 @@ document.addEventListener('alpine:init', () => {
|
||||
similaritySearchLabel: '',
|
||||
similaritySearchError: '',
|
||||
similaritySearchStats: { loading: false, tracks: 0, artists: 0, peers: 0, elapsed_ms: 0 },
|
||||
federationSearch: { loading: false, error: '', artists: [], releases: [], tracks: [], podcasts: [] },
|
||||
federationSearch: { loading: false, error: '', artists: [], releases: [], tracks: [], podcasts: [], podcastDiscovery: '' },
|
||||
artistFederation: { loading: false, error: '', releases: [], tracks: [] },
|
||||
federationPreparing: {},
|
||||
federationFailures: {},
|
||||
@@ -5293,7 +5293,7 @@ document.addEventListener('alpine:init', () => {
|
||||
this.similaritySearchError = '';
|
||||
this.searchLoading = true;
|
||||
this.searchResults = null;
|
||||
this.federationSearch = { loading: true, error: '', artists: [], releases: [], tracks: [], podcasts: [] };
|
||||
this.federationSearch = { loading: true, error: '', artists: [], releases: [], tracks: [], podcasts: [], podcastDiscovery: '' };
|
||||
this.similaritySearchStats = { loading: true, tracks: 0, artists: 0, peers: 0, elapsed_ms: 0 };
|
||||
Alpine.store('info').close();
|
||||
try {
|
||||
@@ -5435,12 +5435,12 @@ document.addEventListener('alpine:init', () => {
|
||||
this._federationSearchSource.close();
|
||||
this._federationSearchSource = null;
|
||||
}
|
||||
this.federationSearch = { loading: false, error: '', artists: [], releases: [], tracks: [], podcasts: [] };
|
||||
this.federationSearch = { loading: false, error: '', artists: [], releases: [], tracks: [], podcasts: [], podcastDiscovery: '' };
|
||||
},
|
||||
|
||||
startFederationSearch(query) {
|
||||
this.stopFederationSearch();
|
||||
this.federationSearch = { loading: true, error: '', artists: [], releases: [], tracks: [], podcasts: [] };
|
||||
this.federationSearch = { loading: true, error: '', artists: [], releases: [], tracks: [], podcasts: [], podcastDiscovery: '' };
|
||||
const source = new EventSource(`/api/player/federation/search/events?q=${encodeURIComponent(query)}`);
|
||||
this._federationSearchSource = source;
|
||||
const updateResults = (kind, keyFor, labelFor, entity) => {
|
||||
@@ -5507,10 +5507,17 @@ document.addEventListener('alpine:init', () => {
|
||||
podcasts.sort((left, right) => left.rank - right.rank);
|
||||
this.federationSearch = { ...this.federationSearch, podcasts };
|
||||
});
|
||||
source.addEventListener('search.completed', () => {
|
||||
source.addEventListener('search.completed', event => {
|
||||
window.clearTimeout(watchdog);
|
||||
// `running`, `off` or `failed`: a failed podcast search must
|
||||
// not look like "no podcasts found".
|
||||
let podcastDiscovery = '';
|
||||
try {
|
||||
const state = JSON.parse(event?.data)?.entity?.podcast_discovery;
|
||||
if (['running', 'off', 'failed'].includes(state)) podcastDiscovery = state;
|
||||
} catch {}
|
||||
if (this._federationSearchSource === source) {
|
||||
this.federationSearch = { ...this.federationSearch, loading: false };
|
||||
this.federationSearch = { ...this.federationSearch, loading: false, podcastDiscovery };
|
||||
}
|
||||
source.close();
|
||||
if (this._federationSearchSource === source) this._federationSearchSource = null;
|
||||
|
||||
@@ -657,6 +657,9 @@
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
<div class="federation-search-status podcast-search-failed"
|
||||
x-show="!$store.library.similaritySearchLabel && $store.library.federationSearch.podcastDiscovery === 'failed'"
|
||||
x-cloak>{{ t.player_podcast_found_failed }}</div>
|
||||
<template x-for="(track, idx) in $store.library.federationSearch.tracks"
|
||||
:key="track.key.content_id">
|
||||
<div class="track-row federation-track-row"
|
||||
|
||||
@@ -1216,11 +1216,30 @@ test('the federated search shows podcast cards next to music, ordered by rank',
|
||||
|
||||
source.emit('search.completed', {entity: {partial: false, podcast_discovery: 'running'}});
|
||||
assert.equal(library.federationSearch.loading, false);
|
||||
assert.equal(library.federationSearch.podcastDiscovery, 'running');
|
||||
assert.equal(source.closed, true);
|
||||
// Events of a closed search change nothing.
|
||||
library.startFederationSearch('other');
|
||||
source.emit('federation.podcast', {entity: foundEntity()});
|
||||
assert.deepEqual(Array.from(library.federationSearch.podcasts), []);
|
||||
assert.equal(library.federationSearch.podcastDiscovery, '');
|
||||
|
||||
// A failed podcast search is reported, not shown as "nothing found";
|
||||
// the music results stay.
|
||||
const failing = sources[1];
|
||||
failing.emit('federation.track', {type: 'music', kind: 'federation.track', entity: {key: {content_id: 'b3:2'}, metadata: {title: 'Other'}}});
|
||||
failing.emit('search.completed', {entity: {partial: false, podcast_discovery: 'failed'}});
|
||||
assert.equal(library.federationSearch.podcastDiscovery, 'failed');
|
||||
assert.equal(library.federationSearch.tracks.length, 1);
|
||||
assert.equal(library.federationSearch.error, '');
|
||||
// Unknown states and malformed data are ignored.
|
||||
library.startFederationSearch('third');
|
||||
sources[2].emit('search.completed', {entity: {podcast_discovery: '<b>x</b>'}});
|
||||
assert.equal(library.federationSearch.podcastDiscovery, '');
|
||||
library.startFederationSearch('fourth');
|
||||
sources[3].listeners['search.completed']({data: 'not json'});
|
||||
assert.equal(library.federationSearch.loading, false);
|
||||
assert.equal(library.federationSearch.podcastDiscovery, '');
|
||||
});
|
||||
|
||||
test('a found podcast is previewed, then subscribed with the card id and origin URL', async () => {
|
||||
|
||||
Reference in new issue
Block a user