perf: add checks to avoid duplicate metadata extraction

feat/type-attributes
Tomáš Mládek 2022-09-19 22:58:02 +02:00
parent 9ea1eea3ea
commit 2756d7993b
2 changed files with 53 additions and 29 deletions

View File

@ -19,24 +19,11 @@ impl Extractor for ID3Extractor {
fn get(
&self,
address: &Address,
connection: &UpEndConnection,
_connection: &UpEndConnection,
store: Arc<Box<dyn UpStore + Send + Sync>>,
mut job_container: JobContainer,
) -> Result<Vec<Entry>> {
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)?;
if let Some(file) = files.get(0) {
@ -88,4 +75,29 @@ impl Extractor for ID3Extractor {
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)
}
}

View File

@ -6,7 +6,7 @@ use crate::{
database::{
constants,
entry::{Entry, EntryValue},
stores::{fs::{FILE_MIME_KEY}, UpStore},
stores::{fs::FILE_MIME_KEY, UpStore},
UpEndConnection,
},
util::jobs::{JobContainer, JobState},
@ -22,24 +22,11 @@ impl Extractor for ExifExtractor {
fn get(
&self,
address: &Address,
connection: &UpEndConnection,
_connection: &UpEndConnection,
store: Arc<Box<dyn UpStore + Send + Sync>>,
mut job_container: JobContainer,
) -> Result<Vec<Entry>> {
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)?;
if let Some(file) = files.get(0) {
@ -105,4 +92,29 @@ impl Extractor for ExifExtractor {
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)
}
}