File size: 1,341 Bytes
c3aa9b1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | #!/usr/bin/env node
/**
* Fix missing source fields in existing page cache entries
* This script adds the source field to cache entries based on URL patterns
*/
import { DocumentationService } from '../services/documentation-service.js';
import dotenv from 'dotenv';
dotenv.config();
const docService = new DocumentationService();
console.log('\n🔧 Fixing missing source fields in page cache...\n');
try {
// Load existing page cache
await docService.loadPageCache();
let fixed = 0;
let alreadyHadSource = 0;
for (const [url, entry] of docService.pageCache.entries()) {
if (!entry.source) {
// Infer source from URL
const source = docService.getSourceFromUrl(url);
if (source) {
entry.source = source;
docService.pageCache.set(url, entry);
fixed++;
} else {
console.warn(`⚠️ Could not determine source for: ${url}`);
}
} else {
alreadyHadSource++;
}
}
// Save updated cache
if (fixed > 0) {
await docService.savePageCache();
console.log(`✅ Fixed ${fixed} cache entries`);
}
console.log(`✓ ${alreadyHadSource} entries already had source field`);
console.log(`✓ Total entries: ${docService.pageCache.size}\n`);
} catch (error) {
console.error('❌ Error:', error.message);
process.exit(1);
}
|