diff --git a/src/data/cacheManager.ts b/src/data/cacheManager.ts index c9b4ba0..0cb98b8 100644 --- a/src/data/cacheManager.ts +++ b/src/data/cacheManager.ts @@ -3,9 +3,7 @@ import { Mongo } from '../data/db'; import * as moment from 'moment'; import Movie from '../models/movie'; import { getInTheaterMovieNames } from '../crawler/atmovieInTheaterCrawler'; -import { - getMoviesSchedules, updateMoviesSchedules, -} from '../task/atmoviesTask'; +import { getMoviesSchedules, updateMoviesSchedules } from '../task/atmoviesTask'; import isValideDate from '../helper/isValideDate'; export default class cacheManager { @@ -22,7 +20,7 @@ export default class cacheManager { await cacheManager.setRecentMoviesCache(); // To let the api return data ASAP, we serve the schedules from Redis first await cacheManager.setMoviesSchedulesCache(); - await updateMoviesSchedules() + await updateMoviesSchedules(); await cacheManager.setMoviesSchedulesCache(); } @@ -70,14 +68,11 @@ export default class cacheManager { .get(cacheManager.All_MOVIES) .filter(({ chineseTitle, releaseDate, lineMovieId }: Movie) => { // The movie with yahooId does not have image. - const hasLINEMovieId = Boolean(lineMovieId) - const releaseMoment = isValideDate(releaseDate) - ? moment(releaseDate) - : moment(); + const hasLINEMovieId = Boolean(lineMovieId); + const releaseMoment = isValideDate(releaseDate) ? moment(releaseDate) : moment(); return ( hasLINEMovieId && - (!hasInTheaterData || - inTheaterMovieNames.indexOf(chineseTitle) !== -1) && + (!hasInTheaterData || inTheaterMovieNames.indexOf(chineseTitle) !== -1) && today.diff(releaseMoment, 'days') <= 60 ); }); @@ -89,14 +84,7 @@ export default class cacheManager { console.time('setMoviesSchedulesCache'); try { const allSchedules = await getMoviesSchedules(); - const recentMovieChineseTitles: string[] = cacheManager - .get(cacheManager.RECENT_MOVIES) - .map((movie) => movie.chineseTitle); - const filterdSchedules = allSchedules.filter( - (schedule) => - recentMovieChineseTitles.indexOf(schedule.movieName) !== -1 - ); - cacheManager.set(cacheManager.MOVIES_SCHEDULES, filterdSchedules); + cacheManager.set(cacheManager.MOVIES_SCHEDULES, allSchedules); } catch (ex) { console.error(ex); } diff --git a/src/data/schema.ts b/src/data/schema.ts index cee13ae..4fec8cf 100644 --- a/src/data/schema.ts +++ b/src/data/schema.ts @@ -235,7 +235,9 @@ const scheduleType = new GraphQLObjectType({ movie: { type: MovieType, resolve: (obj: Schedule) => - cacheManager.get(cacheManager.All_MOVIES).find(({ chineseTitle }: Movie) => obj.movieName === chineseTitle), + cacheManager + .get(cacheManager.All_MOVIES) + .find(({ chineseTitle, lineMovieId }: Movie) => obj.movieName === chineseTitle && Boolean(lineMovieId)), }, timesValues: { type: new GraphQLList(GraphQLString),