Ignore:
Timestamp:
12/28/25 20:12:33 (6 months ago)
Author:
Tome <gjorgievtome@…>
Branches:
main
Children:
8a7f936
Parents:
d69e088
Message:

Fix compatibility issues

Location:
database/drizzle/queries
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • database/drizzle/queries/builds.ts

    rd69e088 rae5d054  
    511511            description
    512512        })
    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        });
    515519
    516520    return updated?.id ?? null;
  • database/drizzle/queries/components.ts

    rd69e088 rae5d054  
    278278    switch (componentType) {
    279279        case 'cpu':
    280             compatibleComponents = await getCompatibleCPUs(db, existing, limit, sortCondition);
     280            compatibleComponents = await getCompatibleCPUs(db, existing, existingTDP, limit, sortCondition);
    281281            break;
    282282        case 'motherboard':
     
    287287            break;
    288288        case 'gpu':
    289             compatibleComponents = await getCompatibleGPUs(db, existing, pciExpressSlotsUsed, limit, sortCondition);
     289            compatibleComponents = await getCompatibleGPUs(db, existing, existingTDP, pciExpressSlotsUsed, limit, sortCondition);
    290290            break;
    291291        case 'memory':
     
    317317
    318318// Helper functions for checking component-specific compatibility
    319 async function getCompatibleCPUs(db: Database, existing: any, limit?: number, sortCondition?: any) {
     319async function getCompatibleCPUs(db: Database, existing: any, existingTDP?: number, limit?: number, sortCondition?: any) {
    320320    const conditions = [eq(componentsTable.type, 'cpu')];
    321321
     
    362362        .limit(limit || 100);
    363363
     364    let filteredCPUs = cpus;
     365
    364366    if (existing.cooler?.details?.cpuSockets) {
    365367        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;
    370388}
    371389
     
    517535}
    518536
    519 async function getCompatibleGPUs(db: Database, existing: any, pciExpressSlotsUsed: number, limit?: number, sortCondition?: any) {
     537async function getCompatibleGPUs(db: Database, existing: any, existingTDP: number, pciExpressSlotsUsed: number, limit?: number, sortCondition?: any) {
    520538    const conditions = [eq(componentsTable.type, 'gpu')];
    521539
     
    556574        .limit(limit || 100);
    557575
     576    let filteredGPUs = gpus;
     577
    558578    if (existing.motherboard) {
    559579        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;
    564600}
    565601
Note: See TracChangeset for help on using the changeset viewer.