Frontend updates: caching basic data (json) from CDragon

Implement caching in the patch_detector, consume the cache from API routes in frontend
This commit is contained in:
2026-02-28 00:23:04 +01:00
parent dc09d10f07
commit fe128c0848
18 changed files with 480 additions and 65 deletions

View File

@@ -23,7 +23,7 @@ async function setupDatabase() {
const patchFile = path.join(dataDir, "patches.json");
if(!fs.existsSync(dataDir) || !fs.existsSync(patchFile)) {
fs.mkdirSync(dataDir, { recursive: true });
console.log('📥 No data files found. Downloading latest snapshot...');
console.log('🚫 No data files found. Downloading latest snapshot...');
await downloadAndExtractSnapshot();
}
@@ -90,7 +90,11 @@ async function setupDatabase() {
console.log('✅ Skipping matches import - sufficient data already present');
}
// 7. Run match collector to generate stats
// 7. Fetch CDragon data for the current patch
console.log('🎮 Fetching CDragon data...');
await fetchCDragonData();
// 8. Run match collector to generate stats
console.log('📊 Generating champion stats...');
await generateChampionStats();
@@ -322,6 +326,24 @@ async function generateChampionStats() {
}
}
async function fetchCDragonData() {
try {
console.log('🔄 Running CDragon fetcher...');
// Run the fetch-cdragon script
const fetchCDragonPath = path.join(__dirname, 'fetch-cdragon.js');
execSync(`node ${fetchCDragonPath}`, {
stdio: 'inherit',
cwd: path.join(__dirname, '..')
});
console.log('✅ CDragon data fetched');
} catch (error) {
console.error('❌ Failed to fetch CDragon data:', error);
throw error;
}
}
async function getMatchCount(patchVersion) {
const client = new MongoClient(getMongoUri());
await client.connect();