u
This commit is contained in:
@@ -1,25 +1,18 @@
|
||||
import { GET_CATEGORY_ID_BY_SKU } from '../../sql/article.js';
|
||||
import resolveCategoryAccess from '../category/resolveCategoryAccess.js';
|
||||
import resolveArticleBySku from './resolveArticleBySku.js';
|
||||
import queryBySku from './queryBySku.js';
|
||||
|
||||
export default function getBySku(pool) {
|
||||
const access = resolveCategoryAccess(pool);
|
||||
const resolve = resolveArticleBySku(pool);
|
||||
const load = queryBySku(pool);
|
||||
|
||||
return async (googleAuthId, sku) => {
|
||||
const categoryLookup = await pool
|
||||
.request()
|
||||
.input('sku', sku)
|
||||
.query(GET_CATEGORY_ID_BY_SKU);
|
||||
let t0 = performance.now();
|
||||
const { articleId, languageId } = await resolve(googleAuthId, sku);
|
||||
console.log(`[getBySku] resolveArticleBySku ${(performance.now() - t0).toFixed(1)}ms`);
|
||||
|
||||
const categoryId = categoryLookup.recordset[0]?.categoryId;
|
||||
if (!categoryId) {
|
||||
throw new Error('Article not found');
|
||||
}
|
||||
|
||||
const { languageId } = await access(googleAuthId, categoryId);
|
||||
|
||||
const article = await load(sku, languageId);
|
||||
t0 = performance.now();
|
||||
const article = await load(articleId, languageId);
|
||||
console.log(`[getBySku] queryBySku (parallel) ${(performance.now() - t0).toFixed(1)}ms`);
|
||||
if (!article) {
|
||||
throw new Error('Article not found');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user