Skip to content

Commit

Permalink
refactor(server): build network/studio media without storing them in …
Browse files Browse the repository at this point in the history
…resource cache
  • Loading branch information
ADRFranklin committed Jun 15, 2024
1 parent c5f2312 commit 32b58d3
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 34 deletions.
16 changes: 16 additions & 0 deletions server/src/resources/company/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@ export class CompanyEntity extends BaseEntity<CompanyProps> {
return new CompanyEntity({ id, props });
}

get artwork(): { logo?: { url: string; source: string } } {
return this.props.artwork;
}

get name(): string {
return this.props.name;
}

get providers(): { tmdbId: number } {
return this.props.providers;
}

get source(): string {
return this.props.source;
}

/**
* Validates the Company entity.
*/
Expand Down
4 changes: 2 additions & 2 deletions server/src/resources/company/mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class CompanyMapper
props: {
name: record.name,
artwork: record.artwork,
provider: record.provider,
providers: record.provider,
source: record.source,
},
createdAt: record.createdAt,
Expand All @@ -53,7 +53,7 @@ export class CompanyMapper
toResponse(entity: CompanyEntity): CompanyResponseProps {
const copy = entity.getProps();
return {
id: copy.provider.tmdbId,
id: copy.providers.tmdbId,
name: copy.name,
logo_path: copy.artwork.logo?.url || '',
};
Expand Down
2 changes: 1 addition & 1 deletion server/src/resources/company/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type CompanyProps = {
source: string;
};
};
provider: {
providers: {
tmdbId: number;
};
source: string;
Expand Down
37 changes: 13 additions & 24 deletions server/src/services/cache/cache-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,31 +79,28 @@ export class CacheService {
this.networkService.getNetworks(),
this.companyService.getCompanies(),
]);
const [showDiscovery, movieDiscovery] = await Bluebird.all([
Bluebird.map(networks, async (network) =>
this.showService.getDiscover({
filterByNetworkId: network.providers.tmdbId,
}),
await Bluebird.all([
Bluebird.all(
networks.map(async (network) =>
this.showService.getDiscover({
filterByNetworkId: network.providers.tmdbId,
}),
),
),
Bluebird.map(companies, async (company) =>
this.movieService.getDiscover({
filterByCompanyId: parseInt(company.id, 10),
}),
Bluebird.all(
companies.map(async (company) =>
this.movieService.getDiscover({
filterByCompanyId: company.providers.tmdbId,
}),
),
),
]);

return {
movies: movies.map((movie) => movie.getProps()),
shows: shows.map((show) => show.getProps()),
people: people.map((person) => person.getProps()),
networks: networks.map((network) => network.getProps()),
companies: companies.map((company) => company.getProps()),
showDiscovery: showDiscovery
.flat()
.map((show) => show.getProps()),
movieDiscovery: movieDiscovery
.flat()
.map((movie) => movie.getProps()),
};
},
this.defaultCacheTTL,
Expand All @@ -118,12 +115,6 @@ export class CacheService {
companies: results.companies.map((company) =>
CompanyEntity.create(company),
),
showDiscovery: results.showDiscovery.map((show) =>
ShowEntity.create(show),
),
movieDiscovery: results.movieDiscovery.map((movie) =>
MovieEntity.create(movie),
),
};
} catch (error) {
this.logger.error({ error }, 'Error storing trending data');
Expand All @@ -133,8 +124,6 @@ export class CacheService {
people: [],
networks: [],
companies: [],
showDiscovery: [],
movieDiscovery: [],
};
}
}
Expand Down
4 changes: 0 additions & 4 deletions server/src/services/cache/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ export type CommonResourcesCacheResponse = {
people: PersonProps[];
networks: NetworkProps[];
companies: CompanyProps[];
showDiscovery: ShowProps[];
movieDiscovery: MovieProps[];
};

/**
Expand All @@ -28,6 +26,4 @@ export type CommonResourcesResponse = {
people: PersonEntity[];
networks: NetworkEntity[];
companies: CompanyEntity[];
showDiscovery: ShowEntity[];
movieDiscovery: MovieEntity[];
};
2 changes: 1 addition & 1 deletion server/src/services/company/company-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class CompanyService {
);
return companies.map((company) => {
this.logger.debug(
{ companyId: company.provider.tmdbId, name: company.name },
{ companyId: company.providers.tmdbId, name: company.name },
`got company details`,
);
return CompanyEntity.create(company);
Expand Down
4 changes: 2 additions & 2 deletions server/src/services/company/provider/tmdb/tmdb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ export class CompanyTmdbProvider implements CompanyDetailsProvider {
}
: undefined,
},
provider: {
tmdbId: response.id!,
providers: {
tmdbId: response.id || id,
},
source: 'tmdb',
};
Expand Down

0 comments on commit 32b58d3

Please sign in to comment.