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):

  1. calculateRelevanceScore() - Called for every item in filtered index

    • Logged ~10 messages per item
    • With 962 items = 9,620+ log messages per search!
  2. Filter functions - Called for every item during filtering

    • Logged access control decisions for each item
    • With 962 items = 1,000+ additional messages
  3. 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:


๐Ÿ“Š 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:

Total Removals: ~20 console.log statements from hot paths


๐Ÿงช Testing

To Verify Fix

  1. Hard refresh browser
  2. Open browser console (F12)
  3. Open search (Cmd+K / Ctrl+K)
  4. Type a search query (e.g., "storage")
  5. 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:

  1. โœ… 99.9% reduction in console messages (12,500 โ†’ 10)
  2. โœ… Faster search (no console I/O overhead)
  3. โœ… Clean console (usable for debugging)
  4. โœ… Better performance (no browser lag)

Result: Search now works smoothly with clean, readable console output! ๐ŸŽ‰