Skip to content

Commit

Permalink
Modify v1/search to use the same cache as v2/search (#282)
Browse files Browse the repository at this point in the history
  • Loading branch information
alanna-zhou authored Jan 10, 2020
1 parent f38505f commit 73db08e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ services:
- /usr/src/app/node_modules

ghopper:
image: cornellappdev/transit-ghopper:v1.0.7
image: cornellappdev/transit-ghopper:v1.1.6
ports:
- "8988:8988"

Expand All @@ -28,7 +28,7 @@ services:
- "8987:8987"

live-tracking:
image: cornellappdev/transit-python:v1.0.7
image: cornellappdev/transit-python:v1.1.6
env_file: python.envrc
ports:
- "5000:5000"
11 changes: 2 additions & 9 deletions src/routers/v1/SearchRouter.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
// @flow
import LRU from 'lru-cache';
import type Request from 'express';
import ApplicationRouter from '../../appdev/ApplicationRouter';
import RequestUtils from '../../utils/RequestUtils';
import SearchUtils from '../../utils/SearchUtils';
import Constants from '../../utils/Constants';

const queryToPredictionsCacheOptions = {
max: 10000, // Maximum size of cache
maxAge: 1000 * 60 * 60 * 24 * 5, // Maximum age in milliseconds
};
const queryToPredictionsCache = LRU(queryToPredictionsCacheOptions);
const GOOGLE_PLACE = 'googlePlace';
const GOOGLE_PLACE_LOCATION = '42.4440,-76.5019';

Expand All @@ -29,7 +22,7 @@ class SearchRouter extends ApplicationRouter<Array<Object>> {
}

const query = req.body.query.toLowerCase();
const cachedValue = queryToPredictionsCache.get(query);
const cachedValue = SearchUtils.queryToPredictionsCache.get(query);

const formattedStops = await SearchUtils.getFormattedStopsForQuery(query);

Expand Down Expand Up @@ -70,7 +63,7 @@ class SearchRouter extends ApplicationRouter<Array<Object>> {

if (googlePredictions) {
const filteredPredictions = getFilteredPredictions(googlePredictions, formattedStops);
queryToPredictionsCache.set(query, filteredPredictions);
SearchUtils.queryToPredictionsCache.set(query, filteredPredictions);
return filteredPredictions.concat(formattedStops);
}
}
Expand Down

0 comments on commit 73db08e

Please sign in to comment.