Skip to content

Commit 73db08e

Browse files
authored
Modify v1/search to use the same cache as v2/search (#282)
1 parent f38505f commit 73db08e

2 files changed

Lines changed: 4 additions & 11 deletions

File tree

docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ services:
1313
- /usr/src/app/node_modules
1414

1515
ghopper:
16-
image: cornellappdev/transit-ghopper:v1.0.7
16+
image: cornellappdev/transit-ghopper:v1.1.6
1717
ports:
1818
- "8988:8988"
1919

@@ -28,7 +28,7 @@ services:
2828
- "8987:8987"
2929

3030
live-tracking:
31-
image: cornellappdev/transit-python:v1.0.7
31+
image: cornellappdev/transit-python:v1.1.6
3232
env_file: python.envrc
3333
ports:
3434
- "5000:5000"

src/routers/v1/SearchRouter.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
1-
// @flow
2-
import LRU from 'lru-cache';
31
import type Request from 'express';
42
import ApplicationRouter from '../../appdev/ApplicationRouter';
53
import RequestUtils from '../../utils/RequestUtils';
64
import SearchUtils from '../../utils/SearchUtils';
75
import Constants from '../../utils/Constants';
86

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

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

3124
const query = req.body.query.toLowerCase();
32-
const cachedValue = queryToPredictionsCache.get(query);
25+
const cachedValue = SearchUtils.queryToPredictionsCache.get(query);
3326

3427
const formattedStops = await SearchUtils.getFormattedStopsForQuery(query);
3528

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

7164
if (googlePredictions) {
7265
const filteredPredictions = getFilteredPredictions(googlePredictions, formattedStops);
73-
queryToPredictionsCache.set(query, filteredPredictions);
66+
SearchUtils.queryToPredictionsCache.set(query, filteredPredictions);
7467
return filteredPredictions.concat(formattedStops);
7568
}
7669
}

0 commit comments

Comments
 (0)