114 lines
		
	
	
		
			4.9 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			114 lines
		
	
	
		
			4.9 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| #!/usr/bin/env node
 | |
| 
 | |
| const BASE_URL = process.env.BASE_URL || 'http://localhost:4000';
 | |
| 
 | |
| async function testMetadataEndpoint() {
 | |
|   console.log('\n=== Testing /api/vault/metadata (Metadata-First) ===');
 | |
|   
 | |
|   try {
 | |
|     const start = performance.now();
 | |
|     const response = await fetch(`${BASE_URL}/api/vault/metadata`);
 | |
|     const data = await response.json();
 | |
|     const duration = performance.now() - start;
 | |
|     
 | |
|     const payloadSize = JSON.stringify(data).length;
 | |
|     const payloadSizeMB = (payloadSize / 1024 / 1024).toFixed(2);
 | |
|     const payloadSizeKB = (payloadSize / 1024).toFixed(2);
 | |
|     
 | |
|     console.log(`✓ Loaded ${data.length} notes in ${duration.toFixed(2)}ms`);
 | |
|     console.log(`✓ Payload size: ${payloadSizeMB}MB (${payloadSizeKB}KB)`);
 | |
|     console.log(`✓ Average per note: ${(payloadSize / data.length).toFixed(0)} bytes`);
 | |
|     
 | |
|     return { count: data.length, duration, payloadSize };
 | |
|   } catch (error) {
 | |
|     console.error('✗ Error:', error.message);
 | |
|     return null;
 | |
|   }
 | |
| }
 | |
| 
 | |
| async function testOldVaultEndpoint() {
 | |
|   console.log('\n=== Testing /api/vault (Full Load - OLD) ===');
 | |
|   
 | |
|   try {
 | |
|     const start = performance.now();
 | |
|     const response = await fetch(`${BASE_URL}/api/vault`);
 | |
|     const data = await response.json();
 | |
|     const duration = performance.now() - start;
 | |
|     
 | |
|     const payloadSize = JSON.stringify(data).length;
 | |
|     const payloadSizeMB = (payloadSize / 1024 / 1024).toFixed(2);
 | |
|     
 | |
|     console.log(`✓ Loaded ${data.notes?.length || 0} notes in ${duration.toFixed(2)}ms`);
 | |
|     console.log(`✓ Payload size: ${payloadSizeMB}MB`);
 | |
|     console.log(`✓ Average per note: ${(payloadSize / (data.notes?.length || 1)).toFixed(0)} bytes`);
 | |
|     
 | |
|     return { count: data.notes?.length || 0, duration, payloadSize };
 | |
|   } catch (error) {
 | |
|     console.error('✗ Error:', error.message);
 | |
|     return null;
 | |
|   }
 | |
| }
 | |
| 
 | |
| async function testFileListEndpoint() {
 | |
|   console.log('\n=== Testing /api/files/list (Meilisearch Metadata) ===');
 | |
|   
 | |
|   try {
 | |
|     const start = performance.now();
 | |
|     const response = await fetch(`${BASE_URL}/api/files/list`);
 | |
|     const data = await response.json();
 | |
|     const duration = performance.now() - start;
 | |
|     
 | |
|     const payloadSize = JSON.stringify(data).length;
 | |
|     const payloadSizeMB = (payloadSize / 1024 / 1024).toFixed(2);
 | |
|     
 | |
|     console.log(`✓ Loaded ${data.length} files in ${duration.toFixed(2)}ms`);
 | |
|     console.log(`✓ Payload size: ${payloadSizeMB}MB`);
 | |
|     console.log(`✓ Average per file: ${(payloadSize / data.length).toFixed(0)} bytes`);
 | |
|     
 | |
|     return { count: data.length, duration, payloadSize };
 | |
|   } catch (error) {
 | |
|     console.error('✗ Error:', error.message);
 | |
|     return null;
 | |
|   }
 | |
| }
 | |
| 
 | |
| async function runComparison() {
 | |
|   console.log('╔════════════════════════════════════════════════════════════╗');
 | |
|   console.log('║  Performance Comparison: Metadata-First vs Full Load       ║');
 | |
|   console.log('╚════════════════════════════════════════════════════════════╝');
 | |
|   
 | |
|   const metadata = await testMetadataEndpoint();
 | |
|   const fileList = await testFileListEndpoint();
 | |
|   const full = await testOldVaultEndpoint();
 | |
|   
 | |
|   if (metadata && full) {
 | |
|     console.log('\n╔════════════════════════════════════════════════════════════╗');
 | |
|     console.log('║  Summary & Improvements                                    ║');
 | |
|     console.log('╚════════════════════════════════════════════════════════════╝');
 | |
|     
 | |
|     const speedImprovement = ((full.duration / metadata.duration - 1) * 100).toFixed(0);
 | |
|     const sizeImprovement = ((full.payloadSize / metadata.payloadSize - 1) * 100).toFixed(0);
 | |
|     
 | |
|     console.log(`\n📊 Metadata Endpoint (NEW):`);
 | |
|     console.log(`   Duration: ${metadata.duration.toFixed(2)}ms`);
 | |
|     console.log(`   Payload: ${(metadata.payloadSize / 1024).toFixed(0)}KB`);
 | |
|     
 | |
|     if (fileList) {
 | |
|       console.log(`\n📊 Files List Endpoint (Meilisearch):`);
 | |
|       console.log(`   Duration: ${fileList.duration.toFixed(2)}ms`);
 | |
|       console.log(`   Payload: ${(fileList.payloadSize / 1024).toFixed(0)}KB`);
 | |
|     }
 | |
|     
 | |
|     console.log(`\n📊 Full Vault Endpoint (OLD):`);
 | |
|     console.log(`   Duration: ${full.duration.toFixed(2)}ms`);
 | |
|     console.log(`   Payload: ${(full.payloadSize / 1024 / 1024).toFixed(2)}MB`);
 | |
|     
 | |
|     console.log(`\n✅ Performance Improvements:`);
 | |
|     console.log(`   Speed: ${speedImprovement}% faster`);
 | |
|     console.log(`   Size: ${sizeImprovement}% smaller`);
 | |
|     console.log(`   Startup time reduced from ~${full.duration.toFixed(0)}ms to ~${metadata.duration.toFixed(0)}ms`);
 | |
|   }
 | |
| }
 | |
| 
 | |
| runComparison().catch(console.error);
 |