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
This commit is contained in:
David Snelling 2025-10-28 11:20:45 -07:00
parent 0cf5842f44
commit fe34b1d4f0

View file

@ -1271,17 +1271,12 @@ export class FileSystemStorage extends BaseStorage {
protected async getVerbsBySource_internal(
sourceId: string
): Promise<HNSWVerbWithMetadata[]> {
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<HNSWVerbWithMetadata[]> {
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<HNSWVerbWithMetadata[]> {
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<string[]> {
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