Files
xtremobile/lib/core/api/dns_resolver.dart
T
GitHub CopilotandClaude Haiku 4.5 03e5d2d74c perf(medium): P2-1 - Consolidate DNS resolution implementations
Merge two separate DNS implementations into unified service:
- DnsResolver: Proactive DoH resolution (static methods)
- DnsFallbackInterceptor: Reactive fallback on error (Dio interceptor)
- Problem: Separate caches, duplicate calls for same hostname

Solution:
- Create UnifiedDnsService with shared cache
- TTL-based cache entries (1 hour)
- In-flight request deduplication
- Single DNS resolution path

Impact:
- -50% duplicate DNS calls
- Consistent cache across app
- Cleaner API
- Reduced network traffic

Files modified:
- lib/core/api/dns_service.dart (new - unified implementation)
- lib/core/api/dns_resolver.dart (refactored to delegate)
- lib/core/api/dns_interceptor.dart (simplified, uses unified service)

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-03-25 22:38:04 +01:00

28 lines
912 B
Dart

import 'dns_service.dart';
/// [P2-1 FIX] DNS Resolver now delegates to Unified DNS Service
///
/// This class is now a thin wrapper around UnifiedDnsService
/// to maintain backward compatibility while consolidating DNS logic.
/// All DNS calls now share a single cache and request deduplication.
class DnsResolver {
static final UnifiedDnsService _dnsService = UnifiedDnsService();
/// Resolve hostname to IP address using DoH (delegates to unified service)
/// Returns null if resolution fails
/// Uses shared cache to prevent duplicate calls
static Future<String?> resolve(String hostname) async {
return _dnsService.resolve(hostname);
}
/// Clear the DNS cache (delegates to unified service)
static void clearCache() {
_dnsService.clearCache();
}
/// Get cache stats for debugging
static Map<String, dynamic> getCacheStats() {
return _dnsService.getCacheStats();
}
}