Changeset ae5d054
- Timestamp:
- 12/28/25 20:12:33 (6 months ago)
- Branches:
- main
- Children:
- 8a7f936
- Parents:
- d69e088
- Location:
- database/drizzle/queries
- Files:
-
- 2 edited
-
builds.ts (modified) (1 diff)
-
components.ts (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
database/drizzle/queries/builds.ts
rd69e088 rae5d054 511 511 description 512 512 }) 513 .where(eq(buildsTable.id, buildId)) 514 .returning({ id: buildsTable.id }); 513 .where( 514 eq(buildsTable.id, buildId) 515 ) 516 .returning({ 517 id: buildsTable.id 518 }); 515 519 516 520 return updated?.id ?? null; -
database/drizzle/queries/components.ts
rd69e088 rae5d054 278 278 switch (componentType) { 279 279 case 'cpu': 280 compatibleComponents = await getCompatibleCPUs(db, existing, limit, sortCondition);280 compatibleComponents = await getCompatibleCPUs(db, existing, existingTDP, limit, sortCondition); 281 281 break; 282 282 case 'motherboard': … … 287 287 break; 288 288 case 'gpu': 289 compatibleComponents = await getCompatibleGPUs(db, existing, pciExpressSlotsUsed, limit, sortCondition);289 compatibleComponents = await getCompatibleGPUs(db, existing, existingTDP, pciExpressSlotsUsed, limit, sortCondition); 290 290 break; 291 291 case 'memory': … … 317 317 318 318 // Helper functions for checking component-specific compatibility 319 async function getCompatibleCPUs(db: Database, existing: any, limit?: number, sortCondition?: any) {319 async function getCompatibleCPUs(db: Database, existing: any, existingTDP?: number, limit?: number, sortCondition?: any) { 320 320 const conditions = [eq(componentsTable.type, 'cpu')]; 321 321 … … 362 362 .limit(limit || 100); 363 363 364 let filteredCPUs = cpus; 365 364 366 if (existing.cooler?.details?.cpuSockets) { 365 367 const coolerSockets = existing.cooler.details.cpuSockets.map((s: any) => s.socket); 366 return cpus.filter(cpu => coolerSockets.includes(cpu.socket)); 367 } 368 369 return cpus; 368 filteredCPUs = filteredCPUs.filter(cpu => coolerSockets.includes(cpu.socket)); 369 } 370 371 if(existing.psu?.details?.wattage && existingTDP) { 372 const psuWattage = Number(existing.psu.details.wattage) || 0; 373 374 if (psuWattage > 0) { 375 const budget = psuWattage / 1.2; 376 377 const currentCpuTdp = Number(existing.cpu?.details?.tdp) || 0; 378 const baseWithoutCpu = existingTDP - currentCpuTdp; 379 380 filteredCPUs = filteredCPUs.filter(cpu => { 381 const cpuTdp = Number(cpu.tdp) || 0; 382 return (baseWithoutCpu + cpuTdp) <= budget; 383 }); 384 } 385 } 386 387 return filteredCPUs; 370 388 } 371 389 … … 517 535 } 518 536 519 async function getCompatibleGPUs(db: Database, existing: any, pciExpressSlotsUsed: number, limit?: number, sortCondition?: any) {537 async function getCompatibleGPUs(db: Database, existing: any, existingTDP: number, pciExpressSlotsUsed: number, limit?: number, sortCondition?: any) { 520 538 const conditions = [eq(componentsTable.type, 'gpu')]; 521 539 … … 556 574 .limit(limit || 100); 557 575 576 let filteredGPUs = gpus; 577 558 578 if (existing.motherboard) { 559 579 const availableSlots = Number(existing.motherboard.details.pciExpressSlots); 560 return gpus.filter(() => (pciExpressSlotsUsed + 1) <= availableSlots); 561 } 562 563 return gpus; 580 filteredGPUs = gpus.filter(() => (pciExpressSlotsUsed + 1) <= availableSlots); 581 } 582 583 if(existing.psu?.details?.wattage && existingTDP) { 584 const psuWattage = Number(existing.psu.details.wattage) || 0; 585 586 if (psuWattage > 0) { 587 const budget = psuWattage / 1.2; 588 589 const currentGpuTdp = Number(existing.cpu?.details?.tdp) || 0; 590 const baseWithoutGpu = existingTDP - currentGpuTdp; 591 592 filteredGPUs = filteredGPUs.filter(cpu => { 593 const gpuTdp = Number(cpu.tdp) || 0; 594 return (baseWithoutGpu + gpuTdp) <= budget; 595 }); 596 } 597 } 598 599 return filteredGPUs; 564 600 } 565 601
Note:
See TracChangeset
for help on using the changeset viewer.
