Skip to content

Commit

Permalink
🔧 Do not show yahoo movie in movie schedule
Browse files Browse the repository at this point in the history
  • Loading branch information
Asing1001 committed Nov 12, 2023
1 parent 574aafa commit a08bd91
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
24 changes: 6 additions & 18 deletions src/data/cacheManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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();
}

Expand Down Expand Up @@ -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
);
});
Expand All @@ -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);
}
Expand Down
4 changes: 3 additions & 1 deletion src/data/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit a08bd91

Please sign in to comment.