|
| 1 | +# Dead Code Investigation: query_rs.rs |
| 2 | + |
| 3 | +## Issue Summary |
| 4 | +The public `terraphim-ai` repository has dead code warnings for several methods in `crates/terraphim_middleware/src/haystack/query_rs.rs`: |
| 5 | +- `should_fetch_url()` - line 48 |
| 6 | +- `get_fetched_count()` - line 72 |
| 7 | +- `normalize_document_id()` - line 201 |
| 8 | +- `fetch_and_scrape_content()` - line 336 |
| 9 | +- `scrape_content()` - line 417 |
| 10 | +- `is_critical_url()` - line 1107 |
| 11 | + |
| 12 | +## Root Cause Analysis |
| 13 | + |
| 14 | +### Comparison with terraphim-private Repository |
| 15 | + |
| 16 | +The private repository at `/Users/alex/projects/terraphim/terraphim-private` contains a MORE COMPLETE implementation where these methods ARE actively used: |
| 17 | + |
| 18 | +**Line 353 in private repo:** |
| 19 | +```rust |
| 20 | +match self.fetch_and_scrape_content(&enhanced_doc).await { |
| 21 | +``` |
| 22 | + |
| 23 | +**Line 373 in private repo:** |
| 24 | +```rust |
| 25 | +if self.is_critical_url(&enhanced_doc.url) { |
| 26 | +``` |
| 27 | + |
| 28 | +**Line 403 in private repo:** |
| 29 | +```rust |
| 30 | +let unique_urls_fetched = self.get_fetched_count(); |
| 31 | +``` |
| 32 | + |
| 33 | +**Line 351 in private repo:** |
| 34 | +```rust |
| 35 | +&& self.should_fetch_url(&enhanced_doc.url) |
| 36 | +``` |
| 37 | + |
| 38 | +### What Happened |
| 39 | + |
| 40 | +The public repository has a **SIMPLIFIED** version that: |
| 41 | +1. Removed the content fetching/scraping logic (lines 346-399 in private) |
| 42 | +2. Kept the helper methods but they're no longer called |
| 43 | +3. This creates "dead code" that clippy detects |
| 44 | + |
| 45 | +The private repository has: |
| 46 | +- `FetchStats` struct (lines 14-25) - tracks fetch success/failure |
| 47 | +- `PersistenceStats` struct (lines 28-41) - tracks cache hits/misses |
| 48 | +- Full content enhancement logic with `disable_content_enhancement` flag |
| 49 | +- Active usage of all the "dead" methods |
| 50 | + |
| 51 | +## Resolution Options |
| 52 | + |
| 53 | +### Option 1: Copy Complete Implementation from Private Repo ✅ RECOMMENDED |
| 54 | +**Pros:** |
| 55 | +- Restores full functionality |
| 56 | +- Methods are actually used |
| 57 | +- Better feature parity |
| 58 | +- More robust content fetching |
| 59 | + |
| 60 | +**Cons:** |
| 61 | +- May expose private features |
| 62 | +- Larger codebase |
| 63 | + |
| 64 | +### Option 2: Remove Dead Code (Quick Fix) |
| 65 | +**Pros:** |
| 66 | +- Clean, minimal codebase |
| 67 | +- Passes clippy immediately |
| 68 | + |
| 69 | +**Cons:** |
| 70 | +- Loses functionality |
| 71 | +- Can't easily re-add features later |
| 72 | + |
| 73 | +### Option 3: Keep with `#[allow(dead_code)]` (Current Approach) |
| 74 | +**Pros:** |
| 75 | +- Preserves methods for future use |
| 76 | +- Minimal changes |
| 77 | + |
| 78 | +**Cons:** |
| 79 | +- Keeps unused code |
| 80 | +- Clutters codebase |
| 81 | + |
| 82 | +## Recommended Action Plan |
| 83 | + |
| 84 | +1. **Sync from Private Repo** - Copy the complete implementation: |
| 85 | + - Add `FetchStats` and `PersistenceStats` structs |
| 86 | + - Add `disable_content_enhancement` configuration support |
| 87 | + - Restore full content fetching logic (lines 246-400 from private) |
| 88 | + - Update logging to use `log::warn!` for better visibility |
| 89 | + |
| 90 | +2. **Test Compatibility** - Ensure the enhanced version works with public config |
| 91 | + |
| 92 | +3. **Update Documentation** - Document the `disable_content_enhancement` flag |
| 93 | + |
| 94 | +## Files to Sync |
| 95 | + |
| 96 | +**Source:** `/Users/alex/projects/terraphim/terraphim-private/crates/terraphim_middleware/src/haystack/query_rs.rs` |
| 97 | + |
| 98 | +**Target:** `/Users/alex/projects/terraphim/terraphim-ai/crates/terraphim_middleware/src/haystack/query_rs.rs` |
| 99 | + |
| 100 | +**Key Sections:** |
| 101 | +- Lines 13-41: Add FetchStats and PersistenceStats structs |
| 102 | +- Lines 74-103: Methods already present (remove `#[allow(dead_code)]`) |
| 103 | +- Lines 246-400: Full content enhancement logic with stats tracking |
| 104 | + |
| 105 | +## Immediate Fix (Before Release) |
| 106 | + |
| 107 | +For the v1.0.0 release, we should either: |
| 108 | +1. **Quickly sync from private** (15-20 min) - Better long-term |
| 109 | +2. **Keep `#[allow(dead_code)]` annotations** - Current state works |
| 110 | + |
| 111 | +Given time constraints for release, Option 2 is acceptable for now, but schedule Option 1 for v1.0.1. |
0 commit comments