mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-11 17:27:31 +02:00
Improve data filtering and reduce database query complexity
Refactor database storage to use direct value substitution for WHERE clauses, improving performance and simplifying query construction by removing parameterized queries in server/storage.ts. Also, update user group filtering logic in server/routes.ts to correctly handle optional user groups. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 1e4433b5-47ab-464c-b663-fea2e53367dd Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/1e4433b5-47ab-464c-b663-fea2e53367dd/P1V76jG
This commit is contained in:
1 parent
e3c3ae29bc
commit
c50ef4cea1
4 files changed
+23
-31
No files matched your search
@@ -15,6 +15,10 @@ run = ["npm", "run", "start"]
|
|||||||
localPort = 5000
|
localPort = 5000
|
||||||
externalPort = 80
|
externalPort = 80
|
||||||
|
|
||||||
|
[[ports]]
|
||||||
|
localPort = 33873
|
||||||
|
externalPort = 3003
|
||||||
|
|
||||||
[[ports]]
|
[[ports]]
|
||||||
localPort = 38343
|
localPort = 38343
|
||||||
externalPort = 3000
|
externalPort = 3000
|
||||||
@@ -27,10 +31,6 @@ externalPort = 3002
|
|||||||
localPort = 41343
|
localPort = 41343
|
||||||
externalPort = 3001
|
externalPort = 3001
|
||||||
|
|
||||||
[[ports]]
|
|
||||||
localPort = 43431
|
|
||||||
externalPort = 3003
|
|
||||||
|
|
||||||
[workflows]
|
[workflows]
|
||||||
runButton = "Project"
|
runButton = "Project"
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 149 KiB |
+4
-4
@@ -5040,7 +5040,7 @@ RÉSUMÉ DU SCAN
|
|||||||
|
|
||||||
// Apply role-based filtering
|
// Apply role-based filtering
|
||||||
if (user.role !== 'admin' && user.role !== 'directeur') {
|
if (user.role !== 'admin' && user.role !== 'directeur') {
|
||||||
const userGroupIds = user.groups.map((g: any) => g.groupId);
|
const userGroupIds = user.userGroups?.map((ug: any) => ug.groupId) || [];
|
||||||
filters.groupIds = filters.groupIds
|
filters.groupIds = filters.groupIds
|
||||||
? filters.groupIds.filter(id => userGroupIds.includes(id))
|
? filters.groupIds.filter(id => userGroupIds.includes(id))
|
||||||
: userGroupIds;
|
: userGroupIds;
|
||||||
@@ -5071,7 +5071,7 @@ RÉSUMÉ DU SCAN
|
|||||||
|
|
||||||
// Apply role-based filtering
|
// Apply role-based filtering
|
||||||
if (user.role !== 'admin' && user.role !== 'directeur') {
|
if (user.role !== 'admin' && user.role !== 'directeur') {
|
||||||
const userGroupIds = user.groups.map((g: any) => g.groupId);
|
const userGroupIds = user.userGroups?.map((ug: any) => ug.groupId) || [];
|
||||||
filters.groupIds = filters.groupIds
|
filters.groupIds = filters.groupIds
|
||||||
? filters.groupIds.filter(id => userGroupIds.includes(id))
|
? filters.groupIds.filter(id => userGroupIds.includes(id))
|
||||||
: userGroupIds;
|
: userGroupIds;
|
||||||
@@ -5100,7 +5100,7 @@ RÉSUMÉ DU SCAN
|
|||||||
|
|
||||||
// Apply role-based filtering
|
// Apply role-based filtering
|
||||||
if (user.role !== 'admin' && user.role !== 'directeur') {
|
if (user.role !== 'admin' && user.role !== 'directeur') {
|
||||||
const userGroupIds = user.groups.map((g: any) => g.groupId);
|
const userGroupIds = user.userGroups?.map((ug: any) => ug.groupId) || [];
|
||||||
filters.groupIds = filters.groupIds
|
filters.groupIds = filters.groupIds
|
||||||
? filters.groupIds.filter(id => userGroupIds.includes(id))
|
? filters.groupIds.filter(id => userGroupIds.includes(id))
|
||||||
: userGroupIds;
|
: userGroupIds;
|
||||||
@@ -5153,7 +5153,7 @@ RÉSUMÉ DU SCAN
|
|||||||
|
|
||||||
// Apply role-based filtering
|
// Apply role-based filtering
|
||||||
if (user.role !== 'admin' && user.role !== 'directeur') {
|
if (user.role !== 'admin' && user.role !== 'directeur') {
|
||||||
const userGroupIds = user.groups.map((g: any) => g.groupId);
|
const userGroupIds = user.userGroups?.map((ug: any) => ug.groupId) || [];
|
||||||
filters.groupIds = filters.groupIds
|
filters.groupIds = filters.groupIds
|
||||||
? filters.groupIds.filter(id => userGroupIds.includes(id))
|
? filters.groupIds.filter(id => userGroupIds.includes(id))
|
||||||
: userGroupIds;
|
: userGroupIds;
|
||||||
|
|||||||
+15
-23
@@ -2982,33 +2982,29 @@ export class DatabaseStorage implements IStorage {
|
|||||||
const dateFormat = granularity === 'day' ? 'YYYY-MM-DD' :
|
const dateFormat = granularity === 'day' ? 'YYYY-MM-DD' :
|
||||||
granularity === 'week' ? 'YYYY-IW' : 'YYYY-MM';
|
granularity === 'week' ? 'YYYY-IW' : 'YYYY-MM';
|
||||||
|
|
||||||
// Build WHERE clauses
|
// Build WHERE clauses with direct value substitution
|
||||||
const orderConditions: string[] = [];
|
const orderConditions: string[] = [];
|
||||||
const deliveryConditions: string[] = [];
|
const deliveryConditions: string[] = [];
|
||||||
const params: any[] = [];
|
|
||||||
|
|
||||||
if (filters.startDate) {
|
if (filters.startDate) {
|
||||||
orderConditions.push(`planned_date >= $${params.length + 1}`);
|
const startDate = filters.startDate.toISOString().split('T')[0];
|
||||||
deliveryConditions.push(`scheduled_date >= $${params.length + 1}`);
|
orderConditions.push(`planned_date >= '${startDate}'`);
|
||||||
params.push(filters.startDate.toISOString());
|
deliveryConditions.push(`scheduled_date >= '${startDate}'`);
|
||||||
}
|
}
|
||||||
if (filters.endDate) {
|
if (filters.endDate) {
|
||||||
const endParamIndex = params.length + 1;
|
const endDate = filters.endDate.toISOString().split('T')[0];
|
||||||
orderConditions.push(`planned_date <= $${endParamIndex}`);
|
orderConditions.push(`planned_date <= '${endDate}'`);
|
||||||
deliveryConditions.push(`scheduled_date <= $${endParamIndex}`);
|
deliveryConditions.push(`scheduled_date <= '${endDate}'`);
|
||||||
params.push(filters.endDate.toISOString());
|
|
||||||
}
|
}
|
||||||
if (filters.supplierIds?.length) {
|
if (filters.supplierIds?.length) {
|
||||||
const supplierParamIndex = params.length + 1;
|
const supplierIds = filters.supplierIds.join(',');
|
||||||
orderConditions.push(`supplier_id = ANY($${supplierParamIndex})`);
|
orderConditions.push(`supplier_id IN (${supplierIds})`);
|
||||||
deliveryConditions.push(`supplier_id = ANY($${supplierParamIndex})`);
|
deliveryConditions.push(`supplier_id IN (${supplierIds})`);
|
||||||
params.push(filters.supplierIds);
|
|
||||||
}
|
}
|
||||||
if (filters.groupIds?.length) {
|
if (filters.groupIds?.length) {
|
||||||
const groupParamIndex = params.length + 1;
|
const groupIds = filters.groupIds.join(',');
|
||||||
orderConditions.push(`group_id = ANY($${groupParamIndex})`);
|
orderConditions.push(`group_id IN (${groupIds})`);
|
||||||
deliveryConditions.push(`group_id = ANY($${groupParamIndex})`);
|
deliveryConditions.push(`group_id IN (${groupIds})`);
|
||||||
params.push(filters.groupIds);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const orderWhere = orderConditions.length > 0 ? `WHERE ${orderConditions.join(' AND ')}` : '';
|
const orderWhere = orderConditions.length > 0 ? `WHERE ${orderConditions.join(' AND ')}` : '';
|
||||||
@@ -3023,9 +3019,7 @@ export class DatabaseStorage implements IStorage {
|
|||||||
ORDER BY TO_CHAR(planned_date, '${dateFormat}')
|
ORDER BY TO_CHAR(planned_date, '${dateFormat}')
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const ordersData = params.length > 0
|
const ordersData = await db.execute(sql.raw(ordersSql));
|
||||||
? await db.execute(sql.raw(ordersSql).values(params))
|
|
||||||
: await db.execute(sql.raw(ordersSql));
|
|
||||||
|
|
||||||
// Get deliveries by date using raw SQL
|
// Get deliveries by date using raw SQL
|
||||||
const deliveriesSql = `
|
const deliveriesSql = `
|
||||||
@@ -3036,9 +3030,7 @@ export class DatabaseStorage implements IStorage {
|
|||||||
ORDER BY TO_CHAR(scheduled_date, '${dateFormat}')
|
ORDER BY TO_CHAR(scheduled_date, '${dateFormat}')
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const deliveriesData = params.length > 0
|
const deliveriesData = await db.execute(sql.raw(deliveriesSql));
|
||||||
? await db.execute(sql.raw(deliveriesSql).values(params))
|
|
||||||
: await db.execute(sql.raw(deliveriesSql));
|
|
||||||
|
|
||||||
// Merge data
|
// Merge data
|
||||||
const dataMap = new Map<string, { orders: number; deliveries: number }>();
|
const dataMap = new Map<string, { orders: number; deliveries: number }>();
|
||||||
|
|||||||
Reference in new issue
Block a user