fix: player deadlock related to start_watching

This commit is contained in:
2024-11-29 03:21:48 +01:00
parent e60c2d15d2
commit 634c147ee9
11 changed files with 254 additions and 291 deletions

View File

@@ -1,8 +1,7 @@
use std::{collections::HashMap, path::PathBuf, sync::Arc, time::Instant};
use deadpool_sqlite::Pool;
use tokio::{sync::Mutex, task::JoinSet};
use r2d2::{Pool, PooledConnection};
use r2d2_sqlite::SqliteConnectionManager;
use walkdir::{DirEntry, WalkDir};
use crate::{
@@ -16,11 +15,11 @@ use crate::{
pub struct LibraryService {
#[allow(dead_code)]
state: GrooveState,
pool: Pool<SqliteConnectionManager>,
pool: Pool,
}
impl LibraryService {
pub fn new(state: GrooveState, pool: Pool<SqliteConnectionManager>) -> Self {
pub fn new(state: GrooveState, pool: Pool) -> Self {
Self { state, pool }
}
}
@@ -31,11 +30,7 @@ impl Library for LibraryService {
&self,
_request: tonic::Request<()>,
) -> Result<tonic::Response<TrackList>, tonic::Status> {
let Ok(db) = self.pool.get() else {
return Err(tonic::Status::internal(""));
};
let Ok(tracks) = get_tracks(&db) else {
let Ok(tracks) = get_tracks(&self.pool).await else {
return Err(tonic::Status::internal(""));
};
@@ -58,7 +53,7 @@ impl Library for LibraryService {
pub async fn index_path(
path: PathBuf,
db: PooledConnection<SqliteConnectionManager>,
db: &Pool,
path_id: u64,
) -> Result<(), rusqlite::Error> {
let home = home::home_dir().unwrap();
@@ -103,7 +98,7 @@ pub async fn index_path(
let now = Instant::now();
insert_tracks(db, Arc::try_unwrap(tracks).unwrap().into_inner(), path_id)?;
insert_tracks(db, Arc::try_unwrap(tracks).unwrap().into_inner(), path_id).await?;
let elapsed = now.elapsed();