fix(source): consider season and episode for cache key
This commit is contained in:
parent
b47a512587
commit
ceb520d49d
5 changed files with 48 additions and 27 deletions
|
|
@ -32,8 +32,9 @@ export abstract class Source {
|
||||||
protected abstract handleInternal(ctx: Context, type: ContentType, id: Id): Promise<(SourceResult[])>;
|
protected abstract handleInternal(ctx: Context, type: ContentType, id: Id): Promise<(SourceResult[])>;
|
||||||
|
|
||||||
public async handle(ctx: Context, type: ContentType, id: Id): Promise<(SourceResult[])> {
|
public async handle(ctx: Context, type: ContentType, id: Id): Promise<(SourceResult[])> {
|
||||||
if (this.sourceResultCache.has(id.id)) {
|
const cacheKey = id.toString();
|
||||||
return this.sourceResultCache.get(id.id) as SourceResult[];
|
if (this.sourceResultCache.has(cacheKey)) {
|
||||||
|
return this.sourceResultCache.get(cacheKey) as SourceResult[];
|
||||||
}
|
}
|
||||||
|
|
||||||
let sourceResults: SourceResult[];
|
let sourceResults: SourceResult[];
|
||||||
|
|
@ -47,7 +48,7 @@ export abstract class Source {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.sourceResultCache.set(id.id, sourceResults);
|
this.sourceResultCache.set(cacheKey, sourceResults);
|
||||||
|
|
||||||
return sourceResults;
|
return sourceResults;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,27 +2,33 @@ import { ImdbId } from './ImdbId';
|
||||||
|
|
||||||
describe('can be created from string', () => {
|
describe('can be created from string', () => {
|
||||||
test('splits id properly', () => {
|
test('splits id properly', () => {
|
||||||
const { id, season, episode } = ImdbId.fromString('tt2085059:2:4');
|
const imdbId = ImdbId.fromString('tt2085059:2:4');
|
||||||
|
|
||||||
expect(id).toBe('tt2085059');
|
expect(imdbId.id).toBe('tt2085059');
|
||||||
expect(season).toBe(2);
|
expect(imdbId.season).toBe(2);
|
||||||
expect(episode).toBe(4);
|
expect(imdbId.episode).toBe(4);
|
||||||
|
|
||||||
|
expect(imdbId.toString()).toBe('tt2085059:2:4');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('handles weird 0 prefixes in series and episode', () => {
|
test('handles weird 0 prefixes in series and episode', () => {
|
||||||
const { id, season, episode } = ImdbId.fromString('tt2085059:02:04');
|
const imdbId = ImdbId.fromString('tt2085059:02:04');
|
||||||
|
|
||||||
expect(id).toBe('tt2085059');
|
expect(imdbId.id).toBe('tt2085059');
|
||||||
expect(season).toBe(2);
|
expect(imdbId.season).toBe(2);
|
||||||
expect(episode).toBe(4);
|
expect(imdbId.episode).toBe(4);
|
||||||
|
|
||||||
|
expect(imdbId.toString()).toBe('tt2085059:2:4');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('supports movie with missing series and episode', () => {
|
test('supports movie with missing series and episode', () => {
|
||||||
const { id, season, episode } = ImdbId.fromString('tt2085059');
|
const imdbId = ImdbId.fromString('tt2085059');
|
||||||
|
|
||||||
expect(id).toBe('tt2085059');
|
expect(imdbId.id).toBe('tt2085059');
|
||||||
expect(season).toBeUndefined();
|
expect(imdbId.season).toBeUndefined();
|
||||||
expect(episode).toBeUndefined();
|
expect(imdbId.episode).toBeUndefined();
|
||||||
|
|
||||||
|
expect(imdbId.toString()).toBe('tt2085059');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('throws for empty ids', () => {
|
test('throws for empty ids', () => {
|
||||||
|
|
|
||||||
|
|
@ -22,4 +22,8 @@ export class ImdbId {
|
||||||
idParts[2] ? parseInt(idParts[2]) : undefined,
|
idParts[2] ? parseInt(idParts[2]) : undefined,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public toString(): string {
|
||||||
|
return this.season ? `${this.id}:${this.season}:${this.episode}` : this.id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,27 +2,33 @@ import { TmdbId } from './TmdbId';
|
||||||
|
|
||||||
describe('can be created from string', () => {
|
describe('can be created from string', () => {
|
||||||
test('splits id properly', () => {
|
test('splits id properly', () => {
|
||||||
const { id, season, episode } = TmdbId.fromString('2085059:2:4');
|
const tmdbId = TmdbId.fromString('2085059:2:4');
|
||||||
|
|
||||||
expect(id).toBe(2085059);
|
expect(tmdbId.id).toBe(2085059);
|
||||||
expect(season).toBe(2);
|
expect(tmdbId.season).toBe(2);
|
||||||
expect(episode).toBe(4);
|
expect(tmdbId.episode).toBe(4);
|
||||||
|
|
||||||
|
expect(tmdbId.toString()).toBe('2085059:2:4');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('handles weird 0 prefixes in series and episode', () => {
|
test('handles weird 0 prefixes in series and episode', () => {
|
||||||
const { id, season, episode } = TmdbId.fromString('2085059:02:04');
|
const tmdbId = TmdbId.fromString('2085059:02:04');
|
||||||
|
|
||||||
expect(id).toBe(2085059);
|
expect(tmdbId.id).toBe(2085059);
|
||||||
expect(season).toBe(2);
|
expect(tmdbId.season).toBe(2);
|
||||||
expect(episode).toBe(4);
|
expect(tmdbId.episode).toBe(4);
|
||||||
|
|
||||||
|
expect(tmdbId.toString()).toBe('2085059:2:4');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('supports movie with missing series and episode', () => {
|
test('supports movie with missing series and episode', () => {
|
||||||
const { id, season, episode } = TmdbId.fromString('2085059');
|
const tmdbId = TmdbId.fromString('2085059');
|
||||||
|
|
||||||
expect(id).toBe(2085059);
|
expect(tmdbId.id).toBe(2085059);
|
||||||
expect(season).toBeUndefined();
|
expect(tmdbId.season).toBeUndefined();
|
||||||
expect(episode).toBeUndefined();
|
expect(tmdbId.episode).toBeUndefined();
|
||||||
|
|
||||||
|
expect(tmdbId.toString()).toBe('2085059');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('throws for empty ids', () => {
|
test('throws for empty ids', () => {
|
||||||
|
|
|
||||||
|
|
@ -22,4 +22,8 @@ export class TmdbId {
|
||||||
idParts[2] ? parseInt(idParts[2]) : undefined,
|
idParts[2] ? parseInt(idParts[2]) : undefined,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public toString(): string {
|
||||||
|
return this.season ? `${this.id}:${this.season}:${this.episode}` : `${this.id}`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue