perf: add checks to avoid duplicate metadata extraction
parent
9ea1eea3ea
commit
2756d7993b
|
@ -19,24 +19,11 @@ impl Extractor for ID3Extractor {
|
||||||
fn get(
|
fn get(
|
||||||
&self,
|
&self,
|
||||||
address: &Address,
|
address: &Address,
|
||||||
connection: &UpEndConnection,
|
_connection: &UpEndConnection,
|
||||||
store: Arc<Box<dyn UpStore + Send + Sync>>,
|
store: Arc<Box<dyn UpStore + Send + Sync>>,
|
||||||
mut job_container: JobContainer,
|
mut job_container: JobContainer,
|
||||||
) -> Result<Vec<Entry>> {
|
) -> Result<Vec<Entry>> {
|
||||||
if let Address::Hash(hash) = address {
|
if let Address::Hash(hash) = address {
|
||||||
let is_audio = connection.retrieve_object(address)?.iter().any(|e| {
|
|
||||||
if e.attribute == FILE_MIME_KEY {
|
|
||||||
if let EntryValue::String(mime) = &e.value {
|
|
||||||
return mime.starts_with("audio") || mime == "application/x-riff";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
false
|
|
||||||
});
|
|
||||||
|
|
||||||
if !is_audio {
|
|
||||||
return Ok(vec![]);
|
|
||||||
}
|
|
||||||
|
|
||||||
let files = store.retrieve(hash)?;
|
let files = store.retrieve(hash)?;
|
||||||
|
|
||||||
if let Some(file) = files.get(0) {
|
if let Some(file) = files.get(0) {
|
||||||
|
@ -88,4 +75,29 @@ impl Extractor for ID3Extractor {
|
||||||
Ok(vec![])
|
Ok(vec![])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn is_needed(&self, address: &Address, connection: &UpEndConnection) -> Result<bool> {
|
||||||
|
let is_audio = connection.retrieve_object(address)?.iter().any(|e| {
|
||||||
|
if e.attribute == FILE_MIME_KEY {
|
||||||
|
if let EntryValue::String(mime) = &e.value {
|
||||||
|
return mime.starts_with("audio") || mime == "application/x-riff";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
false
|
||||||
|
});
|
||||||
|
|
||||||
|
if !is_audio {
|
||||||
|
return Ok(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
let is_extracted = !connection
|
||||||
|
.query(format!("(matches @{} (contains \"ID3\") ?)", address).parse()?)?
|
||||||
|
.is_empty();
|
||||||
|
|
||||||
|
if is_extracted {
|
||||||
|
return Ok(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ use crate::{
|
||||||
database::{
|
database::{
|
||||||
constants,
|
constants,
|
||||||
entry::{Entry, EntryValue},
|
entry::{Entry, EntryValue},
|
||||||
stores::{fs::{FILE_MIME_KEY}, UpStore},
|
stores::{fs::FILE_MIME_KEY, UpStore},
|
||||||
UpEndConnection,
|
UpEndConnection,
|
||||||
},
|
},
|
||||||
util::jobs::{JobContainer, JobState},
|
util::jobs::{JobContainer, JobState},
|
||||||
|
@ -22,24 +22,11 @@ impl Extractor for ExifExtractor {
|
||||||
fn get(
|
fn get(
|
||||||
&self,
|
&self,
|
||||||
address: &Address,
|
address: &Address,
|
||||||
connection: &UpEndConnection,
|
_connection: &UpEndConnection,
|
||||||
store: Arc<Box<dyn UpStore + Send + Sync>>,
|
store: Arc<Box<dyn UpStore + Send + Sync>>,
|
||||||
mut job_container: JobContainer,
|
mut job_container: JobContainer,
|
||||||
) -> Result<Vec<Entry>> {
|
) -> Result<Vec<Entry>> {
|
||||||
if let Address::Hash(hash) = address {
|
if let Address::Hash(hash) = address {
|
||||||
let is_photo = connection.retrieve_object(address)?.iter().any(|e| {
|
|
||||||
if e.attribute == FILE_MIME_KEY {
|
|
||||||
if let EntryValue::String(mime) = &e.value {
|
|
||||||
return mime.starts_with("image");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
false
|
|
||||||
});
|
|
||||||
|
|
||||||
if !is_photo {
|
|
||||||
return Ok(vec![]);
|
|
||||||
}
|
|
||||||
|
|
||||||
let files = store.retrieve(hash)?;
|
let files = store.retrieve(hash)?;
|
||||||
|
|
||||||
if let Some(file) = files.get(0) {
|
if let Some(file) = files.get(0) {
|
||||||
|
@ -105,4 +92,29 @@ impl Extractor for ExifExtractor {
|
||||||
Ok(vec![])
|
Ok(vec![])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn is_needed(&self, address: &Address, connection: &UpEndConnection) -> Result<bool> {
|
||||||
|
let is_photo = connection.retrieve_object(address)?.iter().any(|e| {
|
||||||
|
if e.attribute == FILE_MIME_KEY {
|
||||||
|
if let EntryValue::String(mime) = &e.value {
|
||||||
|
return mime.starts_with("image");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
false
|
||||||
|
});
|
||||||
|
|
||||||
|
if !is_photo {
|
||||||
|
return Ok(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
let is_extracted = !connection
|
||||||
|
.query(format!("(matches @{} (contains \"EXIF\") ?)", address).parse()?)?
|
||||||
|
.is_empty();
|
||||||
|
|
||||||
|
if is_extracted {
|
||||||
|
return Ok(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue