Skip to content

Commit

Permalink
refactored localization cache logic
Browse files Browse the repository at this point in the history
  • Loading branch information
nitish-egov committed May 28, 2024
1 parent 5a0b0cd commit 73087b5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Localisation {
// Hold the single instance of the class
private static instance: Localisation;
constructor() {
this.localizationHost=config.host.localizationHost
this.localizationHost = config.host.localizationHost
}
// Public method to provide access to the single instance
public static getInstance(): Localisation {
Expand All @@ -25,13 +25,13 @@ class Localisation {
return Localisation.instance;
}

private getLocalisationMap = (): any => {
//{
return Object.values(this.cachedResponse).reduce((acc: any, curr: any) => {
acc = { ...acc, ...curr };
return acc;
}, {}); //
};
// private getLocalisationMap = (): any => {
// //{
// return Object.values(this.cachedResponse).reduce((acc: any, curr: any) => {
// acc = { ...acc, ...curr };
// return acc;
// }, {}); //
// };
// search localization
public getLocalisedData: any = async (
module: string,
Expand All @@ -46,7 +46,7 @@ class Localisation {
await this.fetchLocalisationMessage(module, locale, tenantId);
}
logger.info(`Found in cache`);
return this.getLocalisationMap();
return this?.cachedResponse?.[`${module}-${locale}`];
};
// fetch localization messages
private fetchLocalisationMessage = async (
Expand Down Expand Up @@ -99,7 +99,7 @@ class Localisation {
const requestBody = { RequestInfo, messages, tenantId };
// Construct URL for localization create endpoint
const url =
this.localizationHost + config.paths.localizationCreate;
this.localizationHost + config.paths.localizationCreate;
// Log the start of the localisation messages creation process
logger.info("Creating the localisation messages");
// Send HTTP POST request to create localisation messages
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { enrichResourceDetails, getLocalizedMessagesHandler, getResponseFromDb,
import { logger } from "../utils/logger";
import { validateCreateRequest, validateDownloadRequest, validateSearchRequest } from "../validators/campaignValidators";
import { validateGenerateRequest } from "../validators/genericValidator";
import { getLocalisationModuleName } from "../utils/localisationUtils";

const generateDataService = async (request: express.Request) => {
// Validate the generate request
Expand Down Expand Up @@ -36,7 +37,11 @@ const downloadDataService = async (request: express.Request) => {
const getBoundaryDataService = async (
request: express.Request
) => {
const localizationMap = await getLocalizedMessagesHandler(request, request?.body?.ResourceDetails?.tenantId || request?.query?.tenantId || 'mz');
const { hierarchyType } = request?.query;
const localizationMapHierarchy = hierarchyType && await getLocalizedMessagesHandler(request, request?.query?.tenantId, getLocalisationModuleName(hierarchyType));
const localizationMapModule = await getLocalizedMessagesHandler(request, request?.query?.tenantId);
const localizationMap = { ...localizationMapHierarchy, ...localizationMapModule };
// const localizationMap = await getLocalizedMessagesHandler(request, request?.body?.ResourceDetails?.tenantId || request?.query?.tenantId || 'mz');
// Retrieve boundary sheet data
const boundarySheetData: any = await getBoundarySheetData(request, localizationMap);
// Create and upload file
Expand Down
5 changes: 3 additions & 2 deletions utilities/project-factory/src/server/utils/genericUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,9 @@ async function fullProcessFlowForNewEntry(newEntryResponse: any, generatedResour
// send message to create toppic
logger.info(`processing the generate request for type ${type}`)
produceModifiedMessages(generatedResource, createGeneratedResourceTopic);
hierarchyType && await getLocalizedMessagesHandler(request, request?.query?.tenantId, getLocalisationModuleName(hierarchyType));
const localizationMap = await getLocalizedMessagesHandler(request, request?.query?.tenantId);
const localizationMapHierarchy = hierarchyType && await getLocalizedMessagesHandler(request, request?.query?.tenantId, getLocalisationModuleName(hierarchyType));
const localizationMapModule = await getLocalizedMessagesHandler(request, request?.query?.tenantId);
const localizationMap = { ...localizationMapHierarchy, ...localizationMapModule };
if (type === 'boundary') {
// get boundary data from boundary relationship search api
const result = await getBoundaryDataService(request);
Expand Down

0 comments on commit 73087b5

Please sign in to comment.