SEARCH CONSOLE SPAM FIX
Comprehensive documentation system guides
Search Console Spam Fix
Date: October 29, 2025
Time: 1:15 PM PST
Status: ๐ BUG FIX COMPLETE
Purpose: Remove excessive console logging that created "infinite loop" appearance during search
๐จ The Problem
When searching, the console was flooded with thousands of log messages that appeared like an infinite loop:
๐ Calculating score for "Storage System Build Flow" with terms: ["storage"]
๐ Title: "storage system build flow", Path: "/GoGrab-Space/libs/..."
๐ Title match for "storage": +15 (total: 15)
๐ Content matches for "storage": 5 * 3 = +15 (total: 30)
... (repeated for 962+ items in search index)
๐ Blocked GoGrab-Space - global search disabled
๐ Blocked Ai-instructions - global search disabled
... (thousands more messages)
Root Cause
The search service had verbose console logging in hot paths (functions called for every item):
calculateRelevanceScore()- Called for every item in filtered index- Logged ~10 messages per item
- With 962 items = 9,620+ log messages per search!
Filter functions - Called for every item during filtering
- Logged access control decisions for each item
- With 962 items = 1,000+ additional messages
Array mapping for debug - Logged full arrays of items
- Created massive nested objects in console
โ The Solution
Removed all verbose logging from hot paths while keeping useful summary logs.
Changes Made
1. Cleaned calculateRelevanceScore() Method
Before (10+ logs per item):
private calculateRelevanceScore(indexed: SearchIndex, searchTerms: string[]): number {
console.log(`๐ Calculating score for "${indexed.title}" with terms:`, searchTerms);
console.log(`๐ Title: "${titleLower}", Path: "${pathLower}"`);
if (titleLower.includes(term)) {
score += 15;
console.log(`๐ Title match for "${term}": +15 (total: ${score})`);
}
// ... 7 more console.log statements
console.log(`๐ Final score for "${indexed.title}": ${score}`);
return score;
}
After (0 logs per item):
private calculateRelevanceScore(indexed: SearchIndex, searchTerms: string[]): number {
// ๐ฏ Removed verbose logging to prevent console spam with 962+ items
if (titleLower.includes(term)) {
score += 15;
}
// ... clean scoring logic
return score;
}
2. Cleaned Access Control Filter
Before (3+ logs per item):
if (!canAccess) {
console.log(`๐ Blocked search result from ${resultProjectId} - no access`);
return false;
}
if (i.visibility === 'private' && resultProjectName !== currentProject) {
console.log(`๐ Blocked private project ${resultProjectName}`);
return false;
}
After (0 logs per item):
if (!canAccess) {
return false;
}
if (i.visibility === 'private' && resultProjectName !== currentProject) {
return false;
}
3. Removed Array Mapping Debug Logs
Before:
console.log('๐ Filtered items:', filteredIndex.map(i => ({
title: i.title,
project: i.projectName
})));
After:
// Removed verbose item list to prevent console spam
4. Removed Unused Variables
Cleaned up variables that were no longer needed after metadata-only optimization:
- Removed
fileExtensionextraction (not used without content loading) - Removed
pathForLoadingtransformation (not used without content loading)
๐ Impact
Before Fix
Search for "storage":
- ๐ Calculating score... (962 items ร 10 logs = 9,620 messages)
- ๐ Blocked... (962 items ร 3 logs = 2,886 messages)
- ๐ Filtered items... (2 massive array logs)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
TOTAL: ~12,500+ console messages per search! ๐ฅ
After Fix
Search for "storage":
- ๐ Search query: storage
- ๐ Filtered index: 962 items
- ๐ Filtered index after access control: 120 items
- ๐ Filtered index after project filtering: 85 items
- ๐ STARTING RELEVANCE SCORING
- ๐ Found 42 results
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
TOTAL: ~10 console messages per search โ
Performance Impact
| Metric | Before | After | Improvement |
|---|---|---|---|
| Console Messages | ~12,500 | ~10 | 99.9% reduction ๐ |
| Search Speed | Slow (console I/O) | Fast | Noticeably faster โก |
| Console Usability | Unusable (spam) | Clean | Much better DX ๐ |
| Browser Performance | Degraded | Normal | No lag ๐ |
๐ฏ Logging Strategy
What We Keep
โ Summary logs - High-level flow information
console.log('๐ Search query:', term);
console.log('๐ Filtered index:', filteredIndex.length);
console.log('๐ STARTING RELEVANCE SCORING');
โ Important state changes
console.log('๐ indexStructureItems: Indexed 20 files (metadata-only)...');
console.log('๐ Search index built with 962 items');
โ Error conditions
console.error('๐ Search error:', error);
console.warn('๐ซ Rate limit reached');
What We Remove
โ Per-item logging in loops
// BAD: Called 962 times
for (const item of items) {
console.log(`Processing ${item.title}`); // โ Remove
}
โ Verbose scoring details
// BAD: Called for every term ร every item
console.log(`Match found: +${score}`); // โ Remove
โ Large array dumps
// BAD: Massive nested objects
console.log('All items:', items.map(i => ({ ...i }))); // โ Remove
๐ ๏ธ Files Modified
apps/docs-angular/src/app/services/search.service.ts
Lines Changed:
- Line 403-420: Simplified path transformation, removed unused variables
- Line 755-779: Removed console.log from access control filter
- Line 786: Removed verbose array mapping
- Line 806: Removed verbose array mapping
- Line 872-919: Removed all console.log from calculateRelevanceScore
Total Removals: ~20 console.log statements from hot paths
๐งช Testing
To Verify Fix
- Hard refresh browser
- Open browser console (F12)
- Open search (Cmd+K / Ctrl+K)
- Type a search query (e.g., "storage")
- Check console:
- โ Should see ~10 summary messages
- โ NO thousands of "Calculating score..." messages
- โ NO "Blocked..." spam
- โ Clean, readable console output
Expected Console Output
๐ Search query: storage
๐ Search mode: content-search
๐ Current project: GoGrab-Space
๐ Filtered index after access control: 120
๐ Filtered index after project filtering: 85
========================================
๐ STARTING RELEVANCE SCORING
========================================
๐ Found 42 results, sorted by relevance
๐ก Lessons Learned
1. Hot Path Logging = Bad
Never put console.log inside functions called repeatedly in loops:
// โ BAD
items.forEach(item => {
console.log(item); // Called N times!
});
// โ
GOOD
console.log('Processing', items.length, 'items');
items.forEach(item => {
// No logging here
});
2. Summary Over Details
Log counts and summaries, not individual items:
// โ BAD
results.forEach(r => console.log('Result:', r));
// โ
GOOD
console.log('Found', results.length, 'results');
if (results.length < 10) console.log('Results:', results); // Only if small
3. Debug vs Production
Consider using a debug flag for verbose logging:
private readonly DEBUG = false; // Toggle for development
if (this.DEBUG) {
console.log('Detailed debug info...');
}
โจ Summary
Fixed console spam by removing 20+ console.log statements from hot paths:
- โ 99.9% reduction in console messages (12,500 โ 10)
- โ Faster search (no console I/O overhead)
- โ Clean console (usable for debugging)
- โ Better performance (no browser lag)
Result: Search now works smoothly with clean, readable console output! ๐