Dead Code Investigation: query_rs.rs
Issue Summary
The public terraphim-ai repository has dead code warnings for several methods in crates/terraphim_middleware/src/haystack/query_rs.rs:
should_fetch_url()- line 48get_fetched_count()- line 72normalize_document_id()- line 201fetch_and_scrape_content()- line 336scrape_content()- line 417is_critical_url()- line 1107
Root Cause Analysis
Comparison with terraphim-private Repository
The private repository at /Users/alex/projects/terraphim/terraphim-private contains a MORE COMPLETE implementation where these methods ARE actively used:
Line 353 in private repo:
match self.fetch_and_scrape_content.await Line 373 in private repo:
if self.is_critical_url Line 403 in private repo:
let unique_urls_fetched = self.get_fetched_count;Line 351 in private repo:
&& self.should_fetch_urlWhat Happened
The public repository has a SIMPLIFIED version that:
- Removed the content fetching/scraping logic (lines 346-399 in private)
- Kept the helper methods but they're no longer called
- This creates "dead code" that clippy detects
The private repository has:
FetchStatsstruct (lines 14-25) - tracks fetch success/failurePersistenceStatsstruct (lines 28-41) - tracks cache hits/misses- Full content enhancement logic with
disable_content_enhancementflag - Active usage of all the "dead" methods
Resolution Options
Option 1: Copy Complete Implementation from Private Repo β RECOMMENDED
Pros:
- Restores full functionality
- Methods are actually used
- Better feature parity
- More robust content fetching
Cons:
- May expose private features
- Larger codebase
Option 2: Remove Dead Code (Quick Fix)
Pros:
- Clean, minimal codebase
- Passes clippy immediately
Cons:
- Loses functionality
- Can't easily re-add features later
Option 3: Keep with #[allow(dead_code)] (Current Approach)
Pros:
- Preserves methods for future use
- Minimal changes
Cons:
- Keeps unused code
- Clutters codebase
Recommended Action Plan
-
Sync from Private Repo - Copy the complete implementation:
- Add
FetchStatsandPersistenceStatsstructs - Add
disable_content_enhancementconfiguration support - Restore full content fetching logic (lines 246-400 from private)
- Update logging to use
log::warn!for better visibility
- Add
-
Test Compatibility - Ensure the enhanced version works with public config
-
Update Documentation - Document the
disable_content_enhancementflag
Files to Sync
Source: /Users/alex/projects/terraphim/terraphim-private/crates/terraphim_middleware/src/haystack/query_rs.rs
Target: /Users/alex/projects/terraphim/terraphim-ai/crates/terraphim_middleware/src/haystack/query_rs.rs
Key Sections:
- Lines 13-41: Add FetchStats and PersistenceStats structs
- Lines 74-103: Methods already present (remove
#[allow(dead_code)]) - Lines 246-400: Full content enhancement logic with stats tracking
Immediate Fix (Before Release)
For the v1.0.0 release, we should either:
- Quickly sync from private (15-20 min) - Better long-term
- Keep
#[allow(dead_code)]annotations - Current state works
Given time constraints for release, Option 2 is acceptable for now, but schedule Option 1 for v1.0.1.