File tree Expand file tree Collapse file tree 2 files changed +24
-20
lines changed Expand file tree Collapse file tree 2 files changed +24
-20
lines changed Original file line number Diff line number Diff line change @@ -446,17 +446,9 @@ impl Database for MysqlDatabase {
446446 return Err ( e)
447447 }
448448
449- let insert_torrent_announce_urls_result: Result < ( ) , DatabaseError > = if let Some ( tracker_url) = & torrent. announce {
450- query ( "INSERT INTO torrust_torrent_announce_urls (torrent_id, tracker_url) VALUES (?, ?)" )
451- . bind ( torrent_id)
452- . bind ( tracker_url)
453- . execute ( & mut tx)
454- . await
455- . map ( |_| ( ) )
456- . map_err ( |_| DatabaseError :: Error )
457- } else {
449+ let insert_torrent_announce_urls_result: Result < ( ) , DatabaseError > = if let Some ( announce_urls) = & torrent. announce_list {
458450 // flatten the nested vec (this will however remove the)
459- let announce_urls = torrent . announce_list . clone ( ) . unwrap ( ) . into_iter ( ) . flatten ( ) . collect :: < Vec < String > > ( ) ;
451+ let announce_urls = announce_urls . iter ( ) . flatten ( ) . collect :: < Vec < & String > > ( ) ;
460452
461453 for tracker_url in announce_urls. iter ( ) {
462454 let _ = query ( "INSERT INTO torrust_torrent_announce_urls (torrent_id, tracker_url) VALUES (?, ?)" )
@@ -469,6 +461,16 @@ impl Database for MysqlDatabase {
469461 }
470462
471463 Ok ( ( ) )
464+ } else {
465+ let tracker_url = torrent. announce . as_ref ( ) . unwrap ( ) ;
466+
467+ query ( "INSERT INTO torrust_torrent_announce_urls (torrent_id, tracker_url) VALUES (?, ?)" )
468+ . bind ( torrent_id)
469+ . bind ( tracker_url)
470+ . execute ( & mut tx)
471+ . await
472+ . map ( |_| ( ) )
473+ . map_err ( |_| DatabaseError :: Error )
472474 } ;
473475
474476 // rollback transaction on error
Original file line number Diff line number Diff line change @@ -442,17 +442,9 @@ impl Database for SqliteDatabase {
442442 return Err ( e)
443443 }
444444
445- let insert_torrent_announce_urls_result: Result < ( ) , DatabaseError > = if let Some ( tracker_url) = & torrent. announce {
446- query ( "INSERT INTO torrust_torrent_announce_urls (torrent_id, tracker_url) VALUES (?, ?)" )
447- . bind ( torrent_id)
448- . bind ( tracker_url)
449- . execute ( & mut tx)
450- . await
451- . map ( |_| ( ) )
452- . map_err ( |_| DatabaseError :: Error )
453- } else {
445+ let insert_torrent_announce_urls_result: Result < ( ) , DatabaseError > = if let Some ( announce_urls) = & torrent. announce_list {
454446 // flatten the nested vec (this will however remove the)
455- let announce_urls = torrent . announce_list . clone ( ) . unwrap ( ) . into_iter ( ) . flatten ( ) . collect :: < Vec < String > > ( ) ;
447+ let announce_urls = announce_urls . iter ( ) . flatten ( ) . collect :: < Vec < & String > > ( ) ;
456448
457449 for tracker_url in announce_urls. iter ( ) {
458450 let _ = query ( "INSERT INTO torrust_torrent_announce_urls (torrent_id, tracker_url) VALUES (?, ?)" )
@@ -465,6 +457,16 @@ impl Database for SqliteDatabase {
465457 }
466458
467459 Ok ( ( ) )
460+ } else {
461+ let tracker_url = torrent. announce . as_ref ( ) . unwrap ( ) ;
462+
463+ query ( "INSERT INTO torrust_torrent_announce_urls (torrent_id, tracker_url) VALUES (?, ?)" )
464+ . bind ( torrent_id)
465+ . bind ( tracker_url)
466+ . execute ( & mut tx)
467+ . await
468+ . map ( |_| ( ) )
469+ . map_err ( |_| DatabaseError :: Error )
468470 } ;
469471
470472 // rollback transaction on error
You can’t perform that action at this time.
0 commit comments