Skip to content

Commit

Permalink
Improve string performance
Browse files Browse the repository at this point in the history
  • Loading branch information
pozylon committed Dec 27, 2024
1 parent 1c8cbab commit a5c6bd2
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions packages/api/src/loaders/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ const loaders = async (unchainedAPI: UnchainedCore): Promise<UnchainedLoaders['l
);
for (const text of texts) {
const locale = localeMap[text.locale.toLowerCase()];
textsMap[`${locale}:${text.assortmentId}`] = text;
textsMap[locale + text.assortmentId] = text;
}
return queries.map((q) => textsMap[`${q.locale.toLowerCase()}:${q.assortmentId}`]);
return queries.map((q) => textsMap[q.locale.toLowerCase() + q.assortmentId]);
}),

assortmentMediaTextLoader: new DataLoader(async (queries) => {
Expand All @@ -132,9 +132,9 @@ const loaders = async (unchainedAPI: UnchainedCore): Promise<UnchainedLoaders['l
);
for (const text of texts) {
const locale = localeMap[text.locale.toLowerCase()];
textsMap[`${locale}:${text.assortmentMediaId}`] = text;
textsMap[locale + text.assortmentMediaId] = text;
}
return queries.map((q) => textsMap[`${q.locale.toLowerCase()}:${q.assortmentMediaId}`]);
return queries.map((q) => textsMap[q.locale.toLowerCase() + q.assortmentMediaId]);
}),

assortmentMediasLoader: new DataLoader(async (queries) => {
Expand Down Expand Up @@ -259,11 +259,9 @@ const loaders = async (unchainedAPI: UnchainedCore): Promise<UnchainedLoaders['l
);
for (const text of texts) {
const locale = localeMap[text.locale.toLowerCase()];
textsMap[`${locale}:${text.filterId}:${text.filterOptionValue}`] = text;
textsMap[locale + text.filterId + text.filterOptionValue] = text;
}
return queries.map(
(q) => textsMap[`${q.locale.toLowerCase()}:${q.filterId}:${q.filterOptionValue}`],
);
return queries.map((q) => textsMap[q.locale.toLowerCase() + q.filterId + q.filterOptionValue]);
}),

productLoader: new DataLoader(async (queries) => {
Expand Down Expand Up @@ -321,9 +319,9 @@ const loaders = async (unchainedAPI: UnchainedCore): Promise<UnchainedLoaders['l
);
for (const text of texts) {
const locale = localeMap[text.locale.toLowerCase()];
textsMap[`${locale}:${text.productId}`] = text;
textsMap[locale + text.productId] = text;
}
return queries.map((q) => textsMap[`${q.locale.toLowerCase()}:${q.productId}`]);
return queries.map((q) => textsMap[q.locale.toLowerCase() + q.productId]);
}),

productMediaTextLoader: new DataLoader(async (queries) => {
Expand All @@ -347,9 +345,9 @@ const loaders = async (unchainedAPI: UnchainedCore): Promise<UnchainedLoaders['l
);
for (const text of texts) {
const locale = localeMap[text.locale.toLowerCase()];
textsMap[`${locale}:${text.productMediaId}`] = text;
textsMap[locale + text.productMediaId] = text;
}
return queries.map((q) => textsMap[`${q.locale.toLowerCase()}:${q.productMediaId}`]);
return queries.map((q) => textsMap[q.locale.toLowerCase() + q.productMediaId]);
}),

productMediasLoader: new DataLoader(async (queries) => {
Expand Down

0 comments on commit a5c6bd2

Please sign in to comment.