diff --git a/src/lib/proxy/proxy-controller.ts b/src/lib/proxy/proxy-controller.ts index 3d233aa3f3..4f26fc9feb 100644 --- a/src/lib/proxy/proxy-controller.ts +++ b/src/lib/proxy/proxy-controller.ts @@ -21,6 +21,7 @@ import NotImplementedError from '../error/not-implemented-error'; import NotFoundError from '../error/notfound-error'; import rateLimit from 'express-rate-limit'; import { minutesToMilliseconds } from 'date-fns'; +import isEqual from 'lodash.isequal'; interface ApiUserRequest< PARAM = any, @@ -174,23 +175,49 @@ export default class FrontendAPIController extends Controller { if (!this.config.flagResolver.isEnabled('embedProxy')) { throw new NotFoundError(); } - const toggles: ProxyFeatureSchema[] = - await this.services.proxyService.getProxyFeatures( + let toggles: ProxyFeatureSchema[]; + let newToggles: ProxyFeatureSchema[] = []; + if (this.config.flagResolver.isEnabled('globalFrontendApiCache')) { + [toggles, newToggles] = await Promise.all([ + this.services.proxyService.getProxyFeatures( + req.user, + FrontendAPIController.createContext(req), + ), + this.services.proxyService.getNewProxyFeatures( + req.user, + FrontendAPIController.createContext(req), + ), + ]); + if ( + !isEqual( + toggles.sort((a, b) => a.name.localeCompare(b.name)), + newToggles.sort((a, b) => a.name.localeCompare(b.name)), + ) + ) { + this.logger.warn( + `old features and new features are different. Old count ${toggles.length}, new count ${newToggles.length}`, + ); + } + } else { + toggles = await this.services.proxyService.getProxyFeatures( req.user, FrontendAPIController.createContext(req), ); - if (this.config.flagResolver.isEnabled('globalFrontendApiCache')) { - // deliberately run comparison without blocking - void this.services.proxyService.compareToggleDefinitions(req.user); } + const returnedToggles = this.config.flagResolver.isEnabled( + 'returnGlobalFrontendApiCache', + ) + ? newToggles + : toggles; + res.set('Cache-control', 'no-cache'); this.services.openApiService.respondWithValidation( 200, res, proxyFeaturesSchema.$id, - { toggles }, + { toggles: returnedToggles }, ); }