Add batch indexing fallback.

If an RSS feed triggered a unique constrains violation, none of it's
items would be indexed resulting in a Podcast without episodes.

This adds a fallback that indexes each item individually if the batch index fails.
This commit is contained in:
Jordan Petridis 2018-02-03 16:02:42 +02:00
parent 92d01ec51a
commit d131c279b9
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6

View File

@ -6,7 +6,7 @@ use rss;
use dbqueries;
use errors::*;
use models::{IndexState, Update};
use models::{Index, IndexState, Update};
use models::{NewEpisode, NewPodcast, Podcast};
use pipeline::*;
@ -47,7 +47,16 @@ impl Feed {
.and_then(|(insert, update)| {
if !insert.is_empty() {
info!("Indexing {} episodes.", insert.len());
dbqueries::index_new_episodes(insert.as_slice())?;
if let Err(err) = dbqueries::index_new_episodes(insert.as_slice()) {
error!("Failed batch indexng, Fallign back to individual indexing.");
error!("Error: {}", err);
insert.iter().for_each(|ep| {
if let Err(err) = ep.index() {
error!("Failed to index episode: {:?}.", ep.title());
error!("Error msg: {}", err);
};
})
}
}
Ok((insert, update))
})