@@ -849,29 +849,28 @@ class MediaItemRepository extends repository<MediaItemBase>({
849849
850850 newItems . forEach ( ( item ) => ( item . lastTimeUpdated = new Date ( ) . getTime ( ) ) ) ;
851851
852- const newItemsId = await Database . knex
853- . batchInsert (
854- this . tableName ,
855- newItems . map (
856- ( item ) : Record < string , unknown > => ( {
857- ...this . serialize ( this . stripValue ( item ) ) ,
858- slug : Database . knex . raw (
859- `(CASE
860- WHEN (
861- ${ Database . knex ( 'mediaItem' )
862- . count ( )
863- . where ( 'slug' , mediaItemSlug ( item ) )
864- . toQuery ( ) } ) = 0
865- THEN '${ mediaItemSlug ( item ) } '
866- ELSE '${ mediaItemSlug ( item ) } -${ randomSlugId ( ) } '
867- END)`
868- ) ,
869- } )
870- ) ,
871- 30
872- )
873- . transacting ( trx )
874- . returning ( 'id' ) ;
852+ const newItemsId : { id : number } [ ] = [ ] ;
853+
854+ for ( const newItem of newItems ) {
855+ const [ res ] = await trx < MediaItemBase > ( this . tableName )
856+ . insert ( {
857+ ...this . serialize ( this . stripValue ( newItem ) ) ,
858+ slug : Database . knex . raw (
859+ `(CASE
860+ WHEN (
861+ ${ Database . knex ( 'mediaItem' )
862+ . count ( )
863+ . where ( 'slug' , mediaItemSlug ( newItem ) )
864+ . toQuery ( ) } ) = 0
865+ THEN '${ mediaItemSlug ( newItem ) } '
866+ ELSE '${ mediaItemSlug ( newItem ) } -${ randomSlugId ( ) } '
867+ END)`
868+ ) ,
869+ } )
870+ . returning < { id : number } [ ] > ( 'id' ) ;
871+
872+ newItemsId . push ( res ) ;
873+ }
875874
876875 const newItemsWithId = _ . merge (
877876 newItems ,
@@ -931,7 +930,11 @@ class MediaItemRepository extends repository<MediaItemBase>({
931930 searchResultId : number ;
932931 } ) [ ]
933932 ) =>
934- _ ( _ . concat ( newItemsWithId , existingItems || existingSearchResults ) )
933+ _ (
934+ _ . cloneDeep (
935+ _ . concat ( newItemsWithId , existingItems || existingSearchResults )
936+ )
937+ )
935938 . sortBy ( 'searchResultId' )
936939 . forEach ( ( item ) => delete item . searchResultId )
937940 . valueOf ( ) ,
0 commit comments