Skip to content

Commit b4abde5

Browse files
committed
refactor: remove unused API utilities and optimize tech snapshot data fetching
1 parent e28e877 commit b4abde5

18 files changed

Lines changed: 80 additions & 567 deletions

File tree

‎.github/workflows/deaditude-cron.yml‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ jobs:
3030
pip install -r deaditude/requirements.txt
3131
3232
- name: Run batch analysis
33+
id: batch
3334
env:
3435
# core
3536
SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
3637
SUPABASE_KEY: ${{ secrets.SUPABASE_KEY }}
37-
ENABLE_REVALIDATION: "true"
38+
ENABLE_REVALIDATION: "false"
3839
DEBUG_LOGGING: ${{ vars.DEBUG_LOGGING || 'false' }}
3940
# GitHub
4041
DEAD_GITHUB_PAT: ${{ secrets.DEAD_GITHUB_PAT }}
@@ -61,6 +62,17 @@ jobs:
6162
run: |
6263
cd deaditude && python -m engine.cli --batch
6364
65+
- name: Trigger Site Rebuild
66+
if: success() && steps.batch.outputs.updated_techs != ''
67+
run: |
68+
curl -L \
69+
-X POST \
70+
-H "Accept: application/vnd.github+json" \
71+
-H "Authorization: Bearer ${{ secrets.DEAD_GITHUB_PAT }}" \
72+
-H "X-GitHub-Api-Version: 2022-11-28" \
73+
https://api.github.com/repos/${{ github.repository }}/dispatches \
74+
-d "{\"event_type\":\"rebuild_site\", \"client_payload\": {\"tech_ids\": \"${{ steps.batch.outputs.updated_techs }}\"}}"
75+
6476
update-badges:
6577
needs: run-analysis
6678
uses: ./.github/workflows/badge-update-reusable.yml

‎.github/workflows/deploy.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ jobs:
5252
PUBLIC_SUPABASE_ANON_KEY: ${{ secrets.NEXT_PUBLIC_SUPABASE_ANON_KEY }}
5353
SITE_URL: "https://${{ github.repository_owner }}.github.io"
5454
BASE_PATH: "/${{ github.event.repository.name }}/"
55+
BUILD_TECHS: ${{ github.event.client_payload.tech_ids || '' }}
5556
- name: Bypass Jekyll
5657
run: touch website/dist/.nojekyll
5758
- name: Deploy to GitHub Pages

‎deaditude/engine/cli.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,11 @@ def run_batch(techTest=None, analyzers=None):
662662
metrics,
663663
score_data)
664664
update_last_checked(tech["id"])
665+
666+
# Track for GITHUB_OUTPUT
667+
if "updated_techs" not in locals():
668+
updated_techs = []
669+
updated_techs.append(tech["id"])
665670
except Exception as e:
666671
logger.error(f"Failed to save {tech['name']} to database:"
667672
f" {e}")
@@ -692,6 +697,14 @@ def run_batch(techTest=None, analyzers=None):
692697
logger.error(f"Scoring failed for {tech['name']}: {e}")
693698
print(f"❌ Scoring failed for {tech['name']}: {e}")
694699

700+
# Write the updated techs to GITHUB_OUTPUT for the Genius Hack
701+
if not DRY_RUN and "GITHUB_OUTPUT" in os.environ and "updated_techs" in locals() and updated_techs:
702+
try:
703+
with open(os.environ["GITHUB_OUTPUT"], "a") as f:
704+
f.write(f"updated_techs={','.join(updated_techs)}\n")
705+
except Exception as e:
706+
logger.error(f"Failed to write to GITHUB_OUTPUT: {e}")
707+
695708

696709
def parse_args():
697710
"""Parse command line arguments."""

‎website/scripts/src/api.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44
import { createClient, SupabaseClient } from '@supabase/supabase-js';
55
import { loadEnvVars } from './env-loader';
6-
import { TechWithScore } from '@/domains/tech/tech.types';
6+
import { TechWithScore } from '../../src/domains/tech/tech.types';
77

88
// Initialize environment
99
const env = loadEnvVars();

‎website/scripts/src/generate-og-images-ci.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* CI version of the OG image generator
55
* Only generates the fallback image to speed up CI builds
66
*/
7-
import { generateFallbackOGImage } from '../../lib/shared/server';
7+
import { generateFallbackOGImage } from '../../src/lib/shared/server';
88
import { loadEnvVars } from './env-loader';
99

1010
// Load environment variables

‎website/scripts/src/generate-og-images.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
* and saving the results as static files. It's designed to be run as part of
66
* the build process to ensure all OG images are pre-generated.
77
*/
8-
import { calculateDeaditudeScore } from '../../lib/shared';
9-
import { generateFallbackOGImage, generateTechOGImage } from '../../lib/shared/server';
8+
import { calculateDeaditudeScore } from '../../src/lib/shared';
9+
import { generateFallbackOGImage, generateTechOGImage } from '../../src/lib/shared/server';
1010
import { loadEnvVars } from './env-loader';
1111
import { getAllTechs } from './api';
1212

‎website/src/domains/index.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
export * from './tech/tech.types';
22
export * from './project/project.types';
3-
export * from './respect/respect.types';

‎website/src/domains/tech/tech.repository.ts‎

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

‎website/src/lib/api/response.ts‎

Lines changed: 0 additions & 78 deletions
This file was deleted.

‎website/src/lib/cn.ts‎

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)