Skip to content

Commit

Permalink
More database performance improvements
Browse files Browse the repository at this point in the history
Fixes #1411
  • Loading branch information
SubJunk committed Dec 6, 2024
1 parent 11f9370 commit c682bf4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/controllers/media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,15 @@ export const getCollection = async(ctx: ParameterizedContext): Promise<Partial<C
export const getVideoV2 = async(ctx: ParameterizedContext): Promise<MediaMetadataInterface> => {
const { title, imdbID }: UmsQueryParams = ctx.query;
const { episode, season, year }: UmsQueryParams = ctx.query;

if (!title && !imdbID) {
throw new ValidationError('title or imdbId is a required parameter');
}

if (season && !episode) {
throw new ValidationError('season must also have an episode number');
}

let { language }: UmsQueryParams = ctx.query;
const [yearNumber] = [year].map(param => param ? Number(param) : null);
const seasonNumber = Number(season);
Expand All @@ -226,10 +235,6 @@ export const getVideoV2 = async(ctx: ParameterizedContext): Promise<MediaMetadat
episodeNumbers = episodes.map(Number);
}

if (!title && !imdbID) {
throw new ValidationError('title or imdbId is a required parameter');
}

if (language && !language.match(/^[a-z]{2}(-[A-Z]{2})?$/)) {
language = undefined;
}
Expand Down
1 change: 1 addition & 0 deletions src/models/MediaMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ const MediaMetadataSchema: Schema = new Schema({
});

MediaMetadataSchema.index({ episode: 1, season: 1, searchMatches: 1 });
MediaMetadataSchema.index({ episode: 1, season: 1, searchMatches: 1, year: 1 });

MediaMetadataSchema.pre<MediaMetadataInterface>('save', function(next) {
if (this.title && this.title.startsWith('Episode #')) {
Expand Down

0 comments on commit c682bf4

Please sign in to comment.