Skip to content

Commit

Permalink
chore(server): improved debug output for common resources
Browse files Browse the repository at this point in the history
  • Loading branch information
ADRFranklin committed Jun 9, 2024
1 parent 5e82c16 commit 3c12219
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 9 deletions.
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 },
{ companyId: company.provider.tmdbId, name: company.name },
`got company details`,
);
return CompanyEntity.create(company);
Expand Down
7 changes: 6 additions & 1 deletion server/src/services/movie/movie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export class MovieService {
options && Object.keys(options).length ? toQueryString(options) : '';
const cacheName = `movie.${id}${optionsAsString}`;
try {
const start = Date.now();
const result = await this.cacheProvider.wrap(
cacheName,
async () => {
Expand All @@ -78,7 +79,6 @@ export class MovieService {
const details = detailsResult.unwrap();
const ratings = ratingProvider?.isOk() ? ratingProvider.unwrap() : {};
const artwork = artworkResult?.isOk() ? artworkResult.unwrap() : {};
this.logger.debug({ movieId: id }, `got movie details`);
return {
...details,
artwork: {
Expand Down Expand Up @@ -109,6 +109,11 @@ export class MovieService {
);
return None;
}
const end = Date.now();
this.logger.debug(
{ movieId: id, name: result.title },
`got movie details in ${end - start}ms`,
);
return Some(MovieEntity.create(result));
} catch (error) {
this.logger.error(
Expand Down
2 changes: 1 addition & 1 deletion server/src/services/network/network-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class NetworkService {
);
return networks.map((network) => {
this.logger.debug(
{ networkId: network.provider.tmdbId },
{ networkId: network.provider.tmdbId, name: network.name },
`got network details`,
);
return NetworkEntity.create(network);
Expand Down
7 changes: 6 additions & 1 deletion server/src/services/person/person-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export class PersonService {
options?: GetDetailsOptions,
): Promise<Option<PersonEntity>> {
try {
const start = Date.now();
const personResult = await this.personDetailsProvider.getDetails(id);
if (!personResult.isOk()) {
return None;
Expand All @@ -67,7 +68,11 @@ export class PersonService {
),
]);
}
this.logger.debug({ personId: id }, `got person details`);
const end = Date.now();
this.logger.debug(
{ personId: id, name: person.name },
`got person details in ${end - start}ms`,
);
return Some(person);
} catch (error) {
this.logger.error({ error }, 'Error fetching person details');
Expand Down
16 changes: 11 additions & 5 deletions server/src/services/show/show-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export class ShowService {
options && Object.keys(options).length ? toQueryString(options) : '';
const cacheName = `show.${id}${optionsAsString}`;
try {
const start = Date.now();
const result = await this.cacheProvider.wrap<ShowProps | undefined>(
cacheName,
async () => {
Expand All @@ -77,10 +78,6 @@ export class ShowService {
const artwork = artworkResult?.isOk()
? artworkResult.unwrap()
: undefined;
this.logger.debug(
{ showId: id, seasons: details.seasons.length },
`got show details`,
);
return {
...details,
artwork: {
Expand Down Expand Up @@ -109,7 +106,16 @@ export class ShowService {
},
this.defaultCacheTTL,
);
return result ? Some(ShowEntity.create(result)) : None;
if (!result) {
this.logger.debug({ showId: id }, 'show not found');
return None;
}
const end = Date.now();
this.logger.debug(
{ showId: id, name: result.title, seasons: result.seasons.length },
`got show details in ${end - start}ms`,
);
return Some(ShowEntity.create(result));
} catch (error) {
this.logger.error(
{ showId: id, error },
Expand Down

0 comments on commit 3c12219

Please sign in to comment.