Update rmp-ipc and add more tracing

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/4/head
trivernis 3 years ago
parent e4ba7f2674
commit ba04083d2c

@ -1,6 +1,6 @@
[package] [package]
name = "mediarepo-api" name = "mediarepo-api"
version = "0.11.1" version = "0.12.0"
edition = "2018" edition = "2018"
license = "gpl-3" license = "gpl-3"
@ -10,7 +10,7 @@ license = "gpl-3"
tracing = "0.1.29" tracing = "0.1.29"
thiserror = "1.0.30" thiserror = "1.0.30"
async-trait = {version = "0.1.51", optional=true} async-trait = {version = "0.1.51", optional=true}
rmp-ipc = {version = "0.10.0", optional=true} rmp-ipc = {version = "0.11.0", optional=true}
parking_lot = {version="0.11.2", optional=true} parking_lot = {version="0.11.2", optional=true}
serde_json = {version="1.0.68", optional=true} serde_json = {version="1.0.68", optional=true}
directories = {version="4.0.1", optional=true} directories = {version="4.0.1", optional=true}

@ -32,6 +32,7 @@ fn build_uri_runtime() -> PluginResult<TokioRuntime> {
Ok(runtime) Ok(runtime)
} }
#[tracing::instrument(level = "debug", skip_all)]
fn once_scheme<R: Runtime>(app: &AppHandle<R>, request: &Request) -> Result<Response> { fn once_scheme<R: Runtime>(app: &AppHandle<R>, request: &Request) -> Result<Response> {
let buf_state = app.state::<BufferState>(); let buf_state = app.state::<BufferState>();
let resource_key = request.uri().trim_start_matches("once://"); let resource_key = request.uri().trim_start_matches("once://");
@ -51,17 +52,20 @@ fn once_scheme<R: Runtime>(app: &AppHandle<R>, request: &Request) -> Result<Resp
} }
} }
#[tracing::instrument(level = "debug", skip_all)]
async fn content_scheme<R: Runtime>(app: &AppHandle<R>, request: &Request) -> Result<Response> { async fn content_scheme<R: Runtime>(app: &AppHandle<R>, request: &Request) -> Result<Response> {
let api_state = app.state::<ApiState>(); let api_state = app.state::<ApiState>();
let buf_state = app.state::<BufferState>(); let buf_state = app.state::<BufferState>();
let hash = request.uri().trim_start_matches("content://"); let hash = request.uri().trim_start_matches("content://");
if let Some(buffer) = buf_state.get_entry(hash) { if let Some(buffer) = buf_state.get_entry(hash) {
tracing::debug!("Fetching content from cache");
ResponseBuilder::new() ResponseBuilder::new()
.status(200) .status(200)
.mimetype(&buffer.mime) .mimetype(&buffer.mime)
.body(buffer.buf) .body(buffer.buf)
} else { } else {
tracing::debug!("Fetching content from daemon");
let api = api_state.api().await?; let api = api_state.api().await?;
let file = api let file = api
.file .file
@ -72,6 +76,7 @@ async fn content_scheme<R: Runtime>(app: &AppHandle<R>, request: &Request) -> Re
.file .file
.read_file(FileIdentifier::Hash(hash.to_string())) .read_file(FileIdentifier::Hash(hash.to_string()))
.await?; .await?;
tracing::debug!("Received {} content bytes", bytes.len());
buf_state.add_entry(hash.to_string(), mime.clone(), bytes.clone()); buf_state.add_entry(hash.to_string(), mime.clone(), bytes.clone());
ResponseBuilder::new() ResponseBuilder::new()
.mimetype(&mime) .mimetype(&mime)
@ -80,6 +85,7 @@ async fn content_scheme<R: Runtime>(app: &AppHandle<R>, request: &Request) -> Re
} }
} }
#[tracing::instrument(level = "debug", skip_all)]
async fn thumb_scheme<R: Runtime>(app: &AppHandle<R>, request: &Request) -> Result<Response> { async fn thumb_scheme<R: Runtime>(app: &AppHandle<R>, request: &Request) -> Result<Response> {
let api_state = app.state::<ApiState>(); let api_state = app.state::<ApiState>();
let buf_state = app.state::<BufferState>(); let buf_state = app.state::<BufferState>();
@ -104,11 +110,13 @@ async fn thumb_scheme<R: Runtime>(app: &AppHandle<R>, request: &Request) -> Resu
.unwrap_or(250); .unwrap_or(250);
if let Some(buffer) = buf_state.get_entry(request.uri()) { if let Some(buffer) = buf_state.get_entry(request.uri()) {
tracing::debug!("Fetching content from cache");
ResponseBuilder::new() ResponseBuilder::new()
.status(200) .status(200)
.mimetype(&buffer.mime) .mimetype(&buffer.mime)
.body(buffer.buf) .body(buffer.buf)
} else { } else {
tracing::debug!("Fetching content from daemon");
let api = api_state.api().await?; let api = api_state.api().await?;
let (thumb, bytes) = api let (thumb, bytes) = api
.file .file
@ -118,6 +126,7 @@ async fn thumb_scheme<R: Runtime>(app: &AppHandle<R>, request: &Request) -> Resu
((height as f32 * 1.2) as u32, (width as f32 * 1.2) as u32), ((height as f32 * 1.2) as u32, (width as f32 * 1.2) as u32),
) )
.await?; .await?;
tracing::debug!("Received {} content bytes", bytes.len());
buf_state.add_entry( buf_state.add_entry(
request.uri().to_string(), request.uri().to_string(),
thumb.mime_type.clone(), thumb.mime_type.clone(),

Loading…
Cancel
Save