File tree Expand file tree Collapse file tree 2 files changed +13
-11
lines changed
server/src/functions/engines Expand file tree Collapse file tree 2 files changed +13
-11
lines changed Original file line number Diff line number Diff line change @@ -9,13 +9,13 @@ beforeAll(() => {
99test ( "recommendation engine" , async ( ) => {
1010 const usersFor101 = await recommendedTo ( 101 , 5 , 0 ) ;
1111 if ( ! usersFor101 . ok ) throw new Error ( ) ;
12- expect ( usersFor101 . value . map ( ( entry ) => entry . u . id ) ) . toEqual ( [ 102 , 103 , 0 ] ) ;
12+ expect ( usersFor101 . value . map ( ( entry ) => entry . u . id ) ) . toEqual ( [ 102 , 103 ] ) ;
1313
1414 const usersFor102 = await recommendedTo ( 102 , 5 , 0 ) ;
1515 if ( ! usersFor102 . ok ) throw new Error ( ) ;
16- expect ( usersFor102 . value . map ( ( entry ) => entry . u . id ) ) . toEqual ( [ 103 , 101 , 0 ] ) ;
16+ expect ( usersFor102 . value . map ( ( entry ) => entry . u . id ) ) . toEqual ( [ 103 , 101 ] ) ;
1717
1818 const usersFor103 = await recommendedTo ( 103 , 5 , 0 ) ;
1919 if ( ! usersFor103 . ok ) throw new Error ( ) ;
20- expect ( usersFor103 . value . map ( ( entry ) => entry . u . id ) ) . toEqual ( [ 102 , 101 , 0 ] ) ;
20+ expect ( usersFor103 . value . map ( ( entry ) => entry . u . id ) ) . toEqual ( [ 102 , 101 ] ) ;
2121} ) ;
Original file line number Diff line number Diff line change @@ -19,14 +19,16 @@ export async function recommendedTo(
1919 try {
2020 const result = await prisma . $queryRawTyped ( sql ( user , limit , offset ) ) ;
2121 return Promise . all (
22- result . map ( async ( res ) => {
23- const user = await getUserByID ( res . id ) ;
24- if ( ! user . ok ) throw new Error ( "not found" ) ; // this shouldn't happen
25- return {
26- count : Number . parseInt ( res . overlap ?. toString ( ) ?? "0" ) ,
27- u : user . value ,
28- } ;
29- } ) ,
22+ result
23+ . filter ( ( res ) => res . id !== 0 ) // memo shouldn't appear in recommendation list, even if they are not matched
24+ . map ( async ( res ) => {
25+ const user = await getUserByID ( res . id ) ;
26+ if ( ! user . ok ) throw new Error ( "not found" ) ; // this shouldn't happen
27+ return {
28+ count : Number . parseInt ( res . overlap ?. toString ( ) ?? "0" ) ,
29+ u : user . value ,
30+ } ;
31+ } ) ,
3032 )
3133 . then ( ( val ) => Ok ( val ) )
3234 . catch ( ( err ) => Err ( err ) ) ;
You can’t perform that action at this time.
0 commit comments