fix init angain again again (hopefully last time)
This commit is contained in:
@@ -180,7 +180,15 @@ fn handle(
|
||||
.get("limit")
|
||||
.and_then(|s| s.parse::<usize>().ok())
|
||||
.unwrap_or(state.search_count);
|
||||
match state.search_yt_sync(&q, limit) {
|
||||
// Release the synchronous state guard BEFORE calling
|
||||
// search_yt_sync — yt-dlp can take 30+ seconds on a slow
|
||||
// network and holding the daemon mutex here would freeze
|
||||
// every other endpoint (including the GUI's `/init`,
|
||||
// `/downloads`, `/now-playing` polls) for the entire
|
||||
// duration. Mirrors the drop-then-call pattern that
|
||||
// `init_sync` already uses.
|
||||
drop(state);
|
||||
match DaemonState::search_yt_sync(&q, limit) {
|
||||
Ok(results) => json_response(200, &serde_json::json!({
|
||||
"query": q,
|
||||
"limit": limit,
|
||||
|
||||
+10
-1
@@ -556,7 +556,16 @@ impl DaemonState {
|
||||
/// non-zero exit are tolerated as much as possible: an empty list is
|
||||
/// returned when nothing parsed, while a yt-dlp startup failure surfaces
|
||||
/// a descriptive error string so the CLI can show it to the user.
|
||||
pub fn search_yt_sync(&self, query: &str, limit: usize) -> Result<Vec<YtCandidate>, String> {
|
||||
///
|
||||
/// Lives as an associated function (no `&self`) so the HTTP handler can
|
||||
/// release the daemon state mutex before spawning yt-dlp. Earlier
|
||||
/// revisions invoked this as `state.search_yt_sync(...)` *while*
|
||||
/// holding the single-threaded `tiny_http` request handler's state
|
||||
/// guard, which froze the entire daemon (including `/init`, `/queue`,
|
||||
/// `/now-playing`) for the full duration of a yt-dlp search — typically
|
||||
/// 30+ seconds on a slow network. Mirrors the lock-free pattern already
|
||||
/// used for `init_sync` below.
|
||||
pub fn search_yt_sync(query: &str, limit: usize) -> Result<Vec<YtCandidate>, String> {
|
||||
let limit = limit.max(1);
|
||||
let src = format!("ytsearch{limit}:{query}");
|
||||
debug!("yt-dlp search: {src}");
|
||||
|
||||
Reference in New Issue
Block a user