@@ -168,6 +168,25 @@ export class TechRepository {
168168 }
169169 }
170170
171+ /**
172+ * Get optimized lightweight snapshots for a tech (for charts)
173+ */
174+ static async getLightweightSnapshotsByTechId ( techId : string ) : Promise < Partial < Snapshot > [ ] > {
175+ try {
176+ const { data, error } = await supabase
177+ . from ( DB_TABLES . TECH_SNAPSHOTS )
178+ . select ( 'id, tech_id, snapshot_date, deaditude_score' )
179+ . eq ( 'tech_id' , techId )
180+ . order ( 'snapshot_date' , { ascending : false } ) ;
181+
182+ if ( error ) throw error ;
183+ return data || [ ] ;
184+ } catch ( error ) {
185+ handleSupabaseError ( error , 'Get lightweight snapshots by tech id' ) ;
186+ return [ ] ;
187+ }
188+ }
189+
171190 /**
172191 * Get all details for a tech by ID
173192 */
@@ -178,12 +197,24 @@ export class TechRepository {
178197 return { tech : null , snapshots : [ ] , projects : [ ] } ;
179198 }
180199
181- // Parallel fetching for better performance
182- const [ snapshots , projects ] = await Promise . all ( [
183- this . getSnapshotsByTechId ( tech . id ) ,
200+ // Fetch the full latest snapshot, lightweight history, and projects in parallel
201+ const [ latestSnapshot , lightweightSnapshots , projects ] = await Promise . all ( [
202+ this . getLatestSnapshotByTechId ( tech . id ) ,
203+ this . getLightweightSnapshotsByTechId ( tech . id ) ,
184204 this . getProjectsByTechId ( tech . id ) ,
185205 ] ) ;
186206
207+ // Construct the snapshots array where index 0 has FULL data, and the rest are lightweight
208+ const snapshots : Snapshot [ ] = [ ] ;
209+ if ( latestSnapshot ) {
210+ snapshots . push ( latestSnapshot ) ;
211+ // Append historical snapshots, filtering out the latest one to avoid duplicates
212+ const others = lightweightSnapshots . filter ( s => s . id !== latestSnapshot . id ) ;
213+ snapshots . push ( ...( others as Snapshot [ ] ) ) ;
214+ } else {
215+ snapshots . push ( ...( lightweightSnapshots as Snapshot [ ] ) ) ;
216+ }
217+
187218 return { tech, snapshots, projects } ;
188219 }
189220}
0 commit comments