Skip to content

Commit

Permalink
Accelerated importing opml (#914)
Browse files Browse the repository at this point in the history
  • Loading branch information
SamTV12345 authored Sep 2, 2024
1 parent e22f15b commit eb27bbc
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions src/controllers/podcast_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,22 +362,25 @@ pub async fn import_podcasts_from_opml(
if !requester.unwrap().is_privileged_user() {
return Err(CustomError::Forbidden);
}
let document = OPML::from_str(&opml.content).unwrap();

spawn_blocking(move || {
let rng = rand::thread_rng();
let environment = ENVIRONMENT_SERVICE.get().unwrap();
let document = OPML::from_str(&opml.content).unwrap();

for outline in document.body.outlines {
let client = get_async_sync_client().build().unwrap();
executor::block_on(insert_outline(
outline.clone(),
client.clone(),
lobby.clone(),
rng.clone(),
environment.clone(),
conn.clone(),
));
let moved_lobby = lobby.clone();
let conn = conn.clone();
thread::spawn(move || {
let rng = rand::thread_rng();
let environment = ENVIRONMENT_SERVICE.get().unwrap();
let client = get_async_sync_client().build().unwrap();
executor::block_on(insert_outline(
outline.clone(),
client.clone(),
moved_lobby,
rng.clone(),
environment.clone(),
conn,
));
});
}
});

Expand Down

0 comments on commit eb27bbc

Please sign in to comment.