1
+ import Bluebird from 'bluebird' ;
1
2
import { Service } from 'diod' ;
2
3
import pino from 'pino' ;
3
4
4
5
import { Logger } from '@/infrastructure/logger/logger' ;
6
+ import is from '@/infrastructure/utils/is' ;
5
7
import { CompanyEntity } from '@/resources/company/entity' ;
6
8
import { MovieEntity } from '@/resources/movie/entity' ;
7
9
import { NetworkEntity } from '@/resources/network/entity' ;
@@ -18,6 +20,8 @@ import { NetworkService } from '@/services/network/network-service';
18
20
import { PersonService } from '@/services/person/person-service' ;
19
21
import { ShowService } from '@/services/show/show-service' ;
20
22
23
+ import { providers } from '../notifications/providers/index' ;
24
+
21
25
@Service ( )
22
26
export class CacheService {
23
27
/**
@@ -67,37 +71,39 @@ export class CacheService {
67
71
await this . cacheProvider . wrap < CommonResourcesCacheResponse > (
68
72
'resources.common' ,
69
73
async ( ) => {
70
- const [
71
- movies ,
72
- shows ,
73
- people ,
74
- networks ,
75
- companies ,
76
- showDiscovery ,
77
- movieDiscovery ,
78
- ] = await Promise . all ( [
79
- this . movieService . getTrending ( 30 ) ,
80
- this . showService . getTrending ( 30 ) ,
81
- this . personService . getTrending ( 30 ) ,
82
- this . networkService . getNetworks ( ) ,
83
- this . companyService . getCompanies ( ) ,
84
- this . showService . getDiscover ( {
85
- page : 1 ,
86
- limit : 30 ,
87
- } ) ,
88
- this . movieService . getDiscover ( {
89
- page : 1 ,
90
- limit : 30 ,
91
- } ) ,
74
+ const [ movies , shows , people , networks , companies ] =
75
+ await Promise . all ( [
76
+ this . movieService . getTrending ( 30 ) ,
77
+ this . showService . getTrending ( 30 ) ,
78
+ this . personService . getTrending ( 30 ) ,
79
+ this . networkService . getNetworks ( ) ,
80
+ this . companyService . getCompanies ( ) ,
81
+ ] ) ;
82
+ const [ showDiscovery , movieDiscovery ] = await Bluebird . all ( [
83
+ Bluebird . map ( networks , async ( network ) =>
84
+ this . showService . getDiscover ( {
85
+ filterByNetworkId : network . providers . tmdbId ,
86
+ } ) ,
87
+ ) ,
88
+ Bluebird . map ( companies , async ( company ) =>
89
+ this . movieService . getDiscover ( {
90
+ filterByCompanyId : parseInt ( company . id , 10 ) ,
91
+ } ) ,
92
+ ) ,
92
93
] ) ;
94
+
93
95
return {
94
96
movies : movies . map ( ( movie ) => movie . getProps ( ) ) ,
95
97
shows : shows . map ( ( show ) => show . getProps ( ) ) ,
96
98
people : people . map ( ( person ) => person . getProps ( ) ) ,
97
99
networks : networks . map ( ( network ) => network . getProps ( ) ) ,
98
100
companies : companies . map ( ( company ) => company . getProps ( ) ) ,
99
- showDiscovery : showDiscovery . map ( ( show ) => show . getProps ( ) ) ,
100
- movieDiscovery : movieDiscovery . map ( ( movie ) => movie . getProps ( ) ) ,
101
+ showDiscovery : showDiscovery
102
+ . flat ( )
103
+ . map ( ( show ) => show . getProps ( ) ) ,
104
+ movieDiscovery : movieDiscovery
105
+ . flat ( )
106
+ . map ( ( movie ) => movie . getProps ( ) ) ,
101
107
} ;
102
108
} ,
103
109
this . defaultCacheTTL ,
0 commit comments