From 1cd3ade77ed179f3a0a89c54434ce6dddb8fda0b Mon Sep 17 00:00:00 2001 From: Michael SCHAL Date: Thu, 19 Mar 2026 21:23:34 +0100 Subject: [PATCH] perf: remove actif filter, increase batchSize, exclude Y articles without sales MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove actif/suspendu filter that caused wrong stats (893€ CA, 249 units) by incorrectly excluding products with sales. The parallel pagination and bulk ranking fixes are sufficient to handle large suppliers. - Increase getMensuelByArticles and getReferentielByArticles batchSize from 20 to 50, reducing sequential batch iterations by ~2.5x. - Filter gamme Y products with zero 12-month sales from returned rows. Reduces grid size (e.g. S053: 14775→fewer rows) without affecting products that actually sold. Y products with sales are preserved. Co-Authored-By: Claude Sonnet 4.6 --- src/features/grid/api/get-product-rows.ts | 32 ++++++++++------------- src/lib/api-ff-client.ts | 4 +-- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/src/features/grid/api/get-product-rows.ts b/src/features/grid/api/get-product-rows.ts index 57110c7..3f6e2f9 100644 --- a/src/features/grid/api/get-product-rows.ts +++ b/src/features/grid/api/get-product-rows.ts @@ -26,26 +26,16 @@ export async function getProductRows(input: GetProductRowsInput): Promise a.suspendu !== true && a.actif !== false); - const suspendedCount = allArticles.length - activeArticles.length; - if (suspendedCount > 0) { - console.log(`[getProductRows] Filtrage: ${activeArticles.length} actifs, ${suspendedCount} suspendus/inactifs exclus des appels API`); - } - // On utilise allArticles pour la grille, activeArticles pour mensuel/referentiel - const articles = allArticles; + const articles = await getArticlesByFournisseur(codeFournisseur); + console.log(`[getProductRows] ${articles.length} articles for ${codeFournisseur}`); // ─── Phase 2 : Mensuel + Commandes (en parallèle) ──────────────────── const { dateDebut, dateFin } = buildLast12MonthsRange(); const [mensuelMap, referentielMap, commandesMap, rankingResult] = await Promise.all([ - getMensuelByArticles(activeArticles, dateDebut, dateFin), - getReferentielByArticles(activeArticles), + getMensuelByArticles(articles, dateDebut, dateFin), + getReferentielByArticles(articles), getCommandesByFournisseur(codeFournisseur), - getRankingByArticles(activeArticles, codeFournisseur), + getRankingByArticles(articles, codeFournisseur), ]); const { rankings: rankingMap, totalRankedProducts } = rankingResult; console.log(`[getProductRows] mensuel data for ${mensuelMap.size}/${articles.length} articles`); @@ -268,9 +258,15 @@ export async function getProductRows(input: GetProductRowsInput): Promise + p.codeGamme !== "Y" || p.totalQuantite > 0 + ); + const excludedY = allRows.length - rows.length; + console.log(`[getProductRows] ${rows.length} produits (${excludedY} gamme Y sans ventes exclus), ${mensuelMap.size} avec données`); return computeProductScores(rows); } catch (error) { diff --git a/src/lib/api-ff-client.ts b/src/lib/api-ff-client.ts index 2328f43..c193b8d 100644 --- a/src/lib/api-ff-client.ts +++ b/src/lib/api-ff-client.ts @@ -326,7 +326,7 @@ export async function getMensuelByArticles( articles: FfArticle[], dateDebut: string, dateFin: string, - batchSize = 20 + batchSize = 50 ): Promise> { const result = new Map(); @@ -412,7 +412,7 @@ export interface FfReferentiel { */ export async function getReferentielByArticles( articles: FfArticle[], - batchSize = 20 + batchSize = 50 ): Promise> { const result = new Map();