From fe34b1d4f0f8031b67133833a2d9f1bac67d2a9d Mon Sep 17 00:00:00 2001 From: David Snelling Date: Tue, 28 Oct 2025 11:20:45 -0700 Subject: [PATCH] chore: remove debug logging from FileSystemStorage for production - Removed 21 debug console.log statements from v4.8.2 and v4.8.3 - Cleaned up getVerbsBySource_internal, getVerbsByTarget_internal, getVerbsByType_internal - Cleaned up getVerbsWithPagination filtering logic - Cleaned up getAllShardedFiles comprehensive logging - Preserved all error handling logic - Production-ready code with bug fixes from v4.8.1-v4.8.3 --- src/storage/adapters/fileSystemStorage.ts | 61 ++--------------------- 1 file changed, 3 insertions(+), 58 deletions(-) diff --git a/src/storage/adapters/fileSystemStorage.ts b/src/storage/adapters/fileSystemStorage.ts index 6000534c..68817ba1 100644 --- a/src/storage/adapters/fileSystemStorage.ts +++ b/src/storage/adapters/fileSystemStorage.ts @@ -1271,17 +1271,12 @@ export class FileSystemStorage extends BaseStorage { protected async getVerbsBySource_internal( sourceId: string ): Promise { - console.log(`[DEBUG] getVerbsBySource_internal called for sourceId: ${sourceId}`) - console.log(`[DEBUG] verbsDir: ${this.verbsDir}`) - // Use the working pagination method with source filter const result = await this.getVerbsWithPagination({ limit: 10000, filter: { sourceId: [sourceId] } }) - console.log(`[DEBUG] Found ${result.items.length} verbs for source ${sourceId}`) - console.log(`[DEBUG] Total verb files found: ${result.totalCount}`) return result.items } @@ -1291,15 +1286,12 @@ export class FileSystemStorage extends BaseStorage { protected async getVerbsByTarget_internal( targetId: string ): Promise { - console.log(`[DEBUG] getVerbsByTarget_internal called for targetId: ${targetId}`) - // Use the working pagination method with target filter const result = await this.getVerbsWithPagination({ limit: 10000, filter: { targetId: [targetId] } }) - - console.log(`[DEBUG] Found ${result.items.length} verbs for target ${targetId}`) + return result.items } @@ -1307,15 +1299,12 @@ export class FileSystemStorage extends BaseStorage { * Get verbs by type */ protected async getVerbsByType_internal(type: string): Promise { - console.log(`[DEBUG] getVerbsByType_internal called for type: ${type}`) - // Use the working pagination method with type filter const result = await this.getVerbsWithPagination({ limit: 10000, filter: { verbType: [type] } }) - console.log(`[DEBUG] Found ${result.items.length} verbs for type ${type}`) return result.items } @@ -1347,13 +1336,11 @@ export class FileSystemStorage extends BaseStorage { try { // Get actual verb files first (critical for accuracy) const verbFiles = await this.getAllShardedFiles(this.verbsDir) - console.log(`[DEBUG] getAllShardedFiles returned ${verbFiles.length} files from ${this.verbsDir}`) verbFiles.sort() // Consistent ordering for pagination // Use actual file count - don't trust cached totalVerbCount // This prevents accessing undefined array elements const actualFileCount = verbFiles.length - console.log(`[DEBUG] actualFileCount: ${actualFileCount}, startIndex: ${startIndex}, limit: ${limit}`) // For large datasets, warn about performance if (actualFileCount > 1000000) { @@ -1440,12 +1427,7 @@ export class FileSystemStorage extends BaseStorage { // Check sourceId filter if (filter.sourceId) { const sources = Array.isArray(filter.sourceId) ? filter.sourceId : [filter.sourceId] - console.log(`[DEBUG] Checking verb ${verbWithMetadata.id}: sourceId=${verbWithMetadata.sourceId}, filter=${JSON.stringify(sources)}`) - if (!sources.includes(verbWithMetadata.sourceId)) { - console.log(`[DEBUG] Verb ${verbWithMetadata.id} filtered out (sourceId mismatch)`) - continue - } - console.log(`[DEBUG] Verb ${verbWithMetadata.id} MATCHES source filter!`) + if (!sources.includes(verbWithMetadata.sourceId)) continue } // Check targetId filter @@ -2338,31 +2320,10 @@ export class FileSystemStorage extends BaseStorage { * Traverses all shard subdirectories (00-ff) */ private async getAllShardedFiles(baseDir: string): Promise { - console.log(`[DEBUG] getAllShardedFiles called with baseDir: ${baseDir}`) - console.log(`[DEBUG] Current working directory: ${process.cwd()}`) - console.log(`[DEBUG] Resolved absolute path: ${path.resolve(baseDir)}`) - const allFiles: string[] = [] try { - // Check if directory exists - try { - const baseStat = await fs.promises.stat(baseDir) - console.log(`[DEBUG] baseDir exists: ${baseStat.isDirectory() ? 'is directory' : 'is NOT directory'}`) - } catch (statError: any) { - console.log(`[DEBUG] baseDir stat failed: ${statError.message}`) - if (statError.code === 'ENOENT') { - console.log(`[DEBUG] baseDir does not exist, returning empty array`) - return [] - } - throw statError - } - const shardDirs = await fs.promises.readdir(baseDir) - console.log(`[DEBUG] Found ${shardDirs.length} entries in baseDir: ${JSON.stringify(shardDirs.slice(0, 10))}${shardDirs.length > 10 ? '...' : ''}`) - - let dirsProcessed = 0 - let filesFound = 0 for (const shardDir of shardDirs) { const shardPath = path.join(baseDir, shardDir) @@ -2371,42 +2332,26 @@ export class FileSystemStorage extends BaseStorage { const stat = await fs.promises.stat(shardPath) if (stat.isDirectory()) { - dirsProcessed++ - console.log(`[DEBUG] Processing shard directory ${dirsProcessed}: ${shardDir}`) - const shardFiles = await fs.promises.readdir(shardPath) - console.log(`[DEBUG] Found ${shardFiles.length} entries in ${shardDir}`) - - let jsonCount = 0 for (const file of shardFiles) { if (file.endsWith('.json')) { allFiles.push(file) - jsonCount++ - filesFound++ } } - console.log(`[DEBUG] Added ${jsonCount} .json files from ${shardDir} (total so far: ${filesFound})`) - } else { - console.log(`[DEBUG] Skipping non-directory entry: ${shardDir}`) } - } catch (shardError: any) { + } catch (shardError) { // Skip inaccessible shard directories - console.log(`[DEBUG] Error accessing shard ${shardDir}: ${shardError.message}`) continue } } - console.log(`[DEBUG] getAllShardedFiles complete: processed ${dirsProcessed} directories, found ${allFiles.length} total .json files`) - // Sort for consistent ordering allFiles.sort() return allFiles } catch (error: any) { - console.log(`[DEBUG] getAllShardedFiles error: ${error.message}, code: ${error.code}`) if (error.code === 'ENOENT') { // Directory doesn't exist yet - console.log(`[DEBUG] Directory does not exist, returning empty array`) return [] } throw error