UNPKG

nostr-deploy-server

Version:

Node.js server for hosting static websites under npub subdomains using Nostr protocol and Blossom servers

133 lines 5.92 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CacheDebugger = void 0; const cache_1 = require("./cache"); const logger_1 = require("./logger"); /** * Cache debugging utility * Helps diagnose cache issues and verify cache behavior */ class CacheDebugger { /** * Test cache operations for a specific pubkey */ static async testPubkeyCache(pubkey) { logger_1.logger.info(`🔍 Cache Debug: Testing cache for pubkey: ${pubkey.substring(0, 8)}...`); // Test relay list cache logger_1.logger.info('📡 Testing relay list cache...'); const relays = await cache_1.CacheService.getRelaysForPubkey(pubkey); if (relays) { logger_1.logger.info(` ✅ Relay list found: ${relays.length} relays`); logger_1.logger.debug(` Relays: ${relays.slice(0, 3).join(', ')}${relays.length > 3 ? '...' : ''}`); } else { logger_1.logger.info(` ❌ No relay list cached`); } // Test blossom servers cache logger_1.logger.info('🌸 Testing blossom servers cache...'); const servers = await cache_1.CacheService.getBlossomServersForPubkey(pubkey); if (servers) { logger_1.logger.info(` ✅ Blossom servers found: ${servers.length} servers`); logger_1.logger.debug(` Servers: ${servers.slice(0, 3).join(', ')}${servers.length > 3 ? '...' : ''}`); } else { logger_1.logger.info(` ❌ No blossom servers cached`); } // Test common file paths const testPaths = ['/index.html', '/', '/about.html', '/404.html']; logger_1.logger.info('📄 Testing file mapping cache...'); for (const path of testPaths) { const mapping = await cache_1.CacheService.getBlobForPath(pubkey, path); if (mapping) { logger_1.logger.info(` ✅ ${path}${mapping.sha256.substring(0, 8)}... (cached ${new Date(mapping.created_at * 1000).toISOString()})`); } else { logger_1.logger.info(` ❌ ${path} not cached`); } } } /** * Test domain to pubkey mapping */ static async testDomainCache(domain) { logger_1.logger.info(`🌐 Cache Debug: Testing domain cache for: ${domain}`); const pubkey = await cache_1.CacheService.getPubkeyForDomain(domain); if (pubkey) { logger_1.logger.info(` ✅ Domain mapped: ${domain}${pubkey.substring(0, 8)}...`); // Test related caches for this pubkey await this.testPubkeyCache(pubkey); } else { logger_1.logger.info(` ❌ Domain not cached: ${domain}`); } } /** * Test cache statistics and health */ static async testCacheHealth() { logger_1.logger.info('🏥 Cache Health Check...'); try { const stats = await cache_1.CacheService.getStats(); logger_1.logger.info(` Backend: ${stats.backend}`); logger_1.logger.info(` Initialized: ${stats.initialized}`); // Test basic cache operations const testKey = `debug-test-${Date.now()}`; const testValue = 'test-value'; // Test domain cache await cache_1.CacheService.setPubkeyForDomain(testKey, testValue); const retrieved = await cache_1.CacheService.getPubkeyForDomain(testKey); if (retrieved === testValue) { logger_1.logger.info(' ✅ Basic cache operations working'); } else { logger_1.logger.error(' ❌ Basic cache operations failing'); logger_1.logger.error(` Expected: ${testValue}, Got: ${retrieved}`); } // Cleanup test data const caches = await cache_1.CacheService['getCaches'](); await caches.pubkeyDomains.delete(testKey); } catch (error) { logger_1.logger.error(' ❌ Cache health check failed:', error); } } /** * Monitor cache activity in real-time */ static startCacheMonitoring() { logger_1.logger.info('🎯 Starting cache monitoring... (use Ctrl+C to stop)'); logger_1.logger.info('Set LOG_LEVEL=debug to see detailed cache hit/miss logs'); // This relies on the debug logs we added to the cache methods logger_1.logger.info('Monitor active - watch for cache HIT/MISS messages in logs'); logger_1.logger.info('Example patterns to look for:'); logger_1.logger.info(' 🎯 = Cache HIT (good!)'); logger_1.logger.info(' 💔 = Cache MISS (investigate if unexpected)'); logger_1.logger.info(' 🚫 = Negative cache HIT (normal for missing content)'); } /** * Force cache invalidation for debugging */ static async invalidateDebugCache(pubkey) { logger_1.logger.info(`🗑️ Force invalidating all cache for pubkey: ${pubkey.substring(0, 8)}...`); try { await cache_1.CacheService.invalidateAllForPubkey(pubkey); logger_1.logger.info(' ✅ Cache invalidation completed'); } catch (error) { logger_1.logger.error(' ❌ Cache invalidation failed:', error); } } /** * Set cache to debug-friendly TTL for testing */ static async enableDebugMode() { logger_1.logger.info('🐛 Enabling cache debug mode...'); logger_1.logger.info('Recommendation: Set these environment variables:'); logger_1.logger.info(' LOG_LEVEL=debug'); logger_1.logger.info(' SLIDING_EXPIRATION=true'); logger_1.logger.info(' CACHE_TIME=3600 (1 hour)'); logger_1.logger.info('Then restart the server to see detailed cache logs'); } } exports.CacheDebugger = CacheDebugger; //# sourceMappingURL=cache-debug.js.map