From ee1b4c405b4381b8aa103678d9db2d64ae34dd32 Mon Sep 17 00:00:00 2001 From: mohitb35 <44917347+mohitb35@users.noreply.github.com> Date: Tue, 15 Oct 2024 20:25:41 +0530 Subject: [PATCH] fix: separates cache key based on API env - purpose: avoid data crossing between systems --- pages/api/data-explorer/species-planted.ts | 6 +++++- pages/api/data-explorer/total-species-planted.ts | 6 +++++- pages/api/data-explorer/total-trees-planted.ts | 6 +++++- pages/api/data-explorer/trees-planted.ts | 6 +++++- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/pages/api/data-explorer/species-planted.ts b/pages/api/data-explorer/species-planted.ts index 55673f3d9b..d5d05d12a5 100644 --- a/pages/api/data-explorer/species-planted.ts +++ b/pages/api/data-explorer/species-planted.ts @@ -26,7 +26,11 @@ handler.post(async (req, response) => { const { projectId, startDate, endDate } = req.body; - const CACHE_KEY = `SPECIES_PLANTED__${getCachedKey( + const cachingKeyPrefix = + process.env.API_ENDPOINT?.replace('https://', '').split('.')[0] || + 'env_missing'; + + const CACHE_KEY = `${cachingKeyPrefix}_SPECIES_PLANTED__${getCachedKey( projectId, startDate, endDate diff --git a/pages/api/data-explorer/total-species-planted.ts b/pages/api/data-explorer/total-species-planted.ts index d3c920da97..d973754ae1 100644 --- a/pages/api/data-explorer/total-species-planted.ts +++ b/pages/api/data-explorer/total-species-planted.ts @@ -26,7 +26,11 @@ handler.post(async (req, response) => { const { projectId, startDate, endDate } = req.body; - const CACHE_KEY = `TOTAL_SPECIES_PLANTED__${getCachedKey( + const cachingKeyPrefix = + process.env.API_ENDPOINT?.replace('https://', '').split('.')[0] || + 'env_missing'; + + const CACHE_KEY = `${cachingKeyPrefix}_TOTAL_SPECIES_PLANTED__${getCachedKey( projectId, startDate, endDate diff --git a/pages/api/data-explorer/total-trees-planted.ts b/pages/api/data-explorer/total-trees-planted.ts index c1414987e5..eead29f922 100644 --- a/pages/api/data-explorer/total-trees-planted.ts +++ b/pages/api/data-explorer/total-trees-planted.ts @@ -26,7 +26,11 @@ handler.post(async (req, response) => { const { projectId, startDate, endDate } = req.body; - const CACHE_KEY = `TOTAL_TREES_PLANTED__${getCachedKey( + const cachingKeyPrefix = + process.env.API_ENDPOINT?.replace('https://', '').split('.')[0] || + 'env_missing'; + + const CACHE_KEY = `${cachingKeyPrefix}_TOTAL_TREES_PLANTED__${getCachedKey( projectId, startDate, endDate diff --git a/pages/api/data-explorer/trees-planted.ts b/pages/api/data-explorer/trees-planted.ts index 43d1e07138..7c3526b64c 100644 --- a/pages/api/data-explorer/trees-planted.ts +++ b/pages/api/data-explorer/trees-planted.ts @@ -33,7 +33,11 @@ handler.post(async (req, response) => { const { projectId, startDate, endDate } = req.body; const { timeFrame } = req.query; - const CACHE_KEY = `TREES_PLANTED__${getCachedKey( + const cachingKeyPrefix = + process.env.API_ENDPOINT?.replace('https://', '').split('.')[0] || + 'env_missing'; + + const CACHE_KEY = `${cachingKeyPrefix}_TREES_PLANTED__${getCachedKey( projectId, startDate, endDate,