@@ -599,7 +599,7 @@ class DbSearcher {
599599 throw new Error ( 'DbSearcher closed' ) ;
600600
601601 if ( ! authorId && ! author )
602- return { author : '' , books : '' } ;
602+ return { author : '' , books : [ ] } ;
603603
604604 this . searchFlag ++ ;
605605
@@ -625,14 +625,60 @@ class DbSearcher {
625625 const rows = await this . restoreBooks ( 'author' , [ authorId ] ) ;
626626
627627 let authorName = '' ;
628- let books = '' ;
628+ let books = [ ] ;
629629
630630 if ( rows . length ) {
631631 authorName = rows [ 0 ] . name ;
632632 books = rows [ 0 ] . books ;
633633 }
634634
635- return { author : authorName , books : ( books && books . length ? JSON . stringify ( books ) : '' ) } ;
635+ return { author : authorName , books} ;
636+ } finally {
637+ this . searchFlag -- ;
638+ }
639+ }
640+
641+ async getAuthorSeriesList ( authorId ) {
642+ if ( this . closed )
643+ throw new Error ( 'DbSearcher closed' ) ;
644+
645+ if ( ! authorId )
646+ return { author : '' , series : [ ] } ;
647+
648+ this . searchFlag ++ ;
649+
650+ try {
651+ const db = this . db ;
652+
653+ //выборка книг автора по authorId
654+ const bookList = await this . getAuthorBookList ( authorId ) ;
655+ const books = bookList . books ;
656+ const seriesSet = new Set ( ) ;
657+ for ( const book of books ) {
658+ if ( book . series )
659+ seriesSet . add ( book . series . toLowerCase ( ) ) ;
660+ }
661+
662+ let series = [ ] ;
663+ if ( seriesSet . size ) {
664+ //выборка серий по названиям
665+ series = await db . select ( {
666+ table : 'series' ,
667+ map : `(r) => ({id: r.id, series: r.name, bookCount: r.bookCount, bookDelCount: r.bookDelCount})` ,
668+ where : `
669+ const seriesArr = ${ db . esc ( Array . from ( seriesSet ) ) } ;
670+ const ids = new Set();
671+ for (const value of seriesArr) {
672+ for (const id of @dirtyIndexLR('value', value, value))
673+ ids.add(id);
674+ }
675+
676+ return ids;
677+ `
678+ } ) ;
679+ }
680+
681+ return { author : bookList . author , series} ;
636682 } finally {
637683 this . searchFlag -- ;
638684 }
@@ -643,7 +689,7 @@ class DbSearcher {
643689 throw new Error ( 'DbSearcher closed' ) ;
644690
645691 if ( ! series )
646- return { books : '' } ;
692+ return { books : [ ] } ;
647693
648694 this . searchFlag ++ ;
649695
@@ -659,7 +705,7 @@ class DbSearcher {
659705 where : `return Array.from(@dirtyIndexLR('value', ${ db . esc ( series ) } , ${ db . esc ( series ) } ))`
660706 } ) ;
661707
662- let books ;
708+ let books = [ ] ;
663709 if ( rows . length && rows [ 0 ] . rawResult . length ) {
664710 //выборка книг серии
665711 const bookRows = await this . restoreBooks ( 'series' , [ rows [ 0 ] . rawResult [ 0 ] ] )
@@ -668,7 +714,7 @@ class DbSearcher {
668714 books = bookRows [ 0 ] . books ;
669715 }
670716
671- return { books : ( books && books . length ? JSON . stringify ( books ) : '' ) } ;
717+ return { books} ;
672718 } finally {
673719 this . searchFlag -- ;
674720 }
0 commit comments