Skip to content

Commit f18225b

Browse files
committed
Add memoization for redirection
1 parent 6f33353 commit f18225b

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed
Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Router } from 'express';
2+
import memoizee from 'memoizee';
23

34
import { EnvVars } from '../config';
45

@@ -8,14 +9,18 @@ export const addTempleAdsRedirection = (
89
isMisesVariable: boolean,
910
templeAdsPathMainPart = path
1011
) => {
12+
const getRedirectionUrl = memoizee(
13+
(extVersion: string, isMisesBrowser: boolean) =>
14+
`${EnvVars.TEMPLE_ADS_API_URL}/v1/api/ads-rules/${extVersion}${templeAdsPathMainPart}${
15+
isMisesVariable ? (isMisesBrowser ? '/mises' : '/no-mises') : ''
16+
}`,
17+
{ max: 1000, normalizer: args => JSON.stringify(args) }
18+
);
19+
1120
router.get(path, (req, res) => {
1221
const { extVersion: rawExtVersion, isMisesBrowser: rawIsMisesBrowser } = req.query;
1322
const extVersion = typeof rawExtVersion === 'string' ? rawExtVersion : '0.0.0';
1423
const isMisesBrowser = rawIsMisesBrowser === 'true';
15-
res.redirect(
16-
`${EnvVars.TEMPLE_ADS_API_URL}/v1/api/ads-rules/${extVersion}${templeAdsPathMainPart}${
17-
isMisesVariable ? (isMisesBrowser ? '/mises' : '/no-mises') : ''
18-
}`
19-
);
24+
res.redirect(getRedirectionUrl(extVersion, isMisesBrowser));
2025
});
2126
};

0 commit comments

Comments
 (0)