fix: comprehensive codebase hardening — crashes, silent failures, performance, and security
Fixes ~95 issues from deep audit across 12 categories in 82 files: - Crash prevention: double-resume in PhotoMetadataExtractor, force unwraps in DateRangePicker, array bounds checks in polls/achievements, ProGate hit-test bypass, Dictionary(uniqueKeysWithValues:) → uniquingKeysWith in 4 files - Silent failure elimination: all 34 try? sites replaced with do/try/catch + logging (SavedTrip, TripDetailView, CanonicalSyncService, BootstrapService, CanonicalModels, CKModels, SportsTimeApp, and more) - Performance: cached DateFormatters (7 files), O(1) team lookups via AppDataProvider, achievement definition dictionary, AnimatedBackground consolidated from 19 Tasks to 1, task cancellation in SharePreviewView - Concurrency: UIKit drawing → MainActor.run, background fetch timeout guard, @MainActor on ThemeManager/AppearanceManager, SyncLogger read/write race fix - Planning engine: game end time in travel feasibility, state-aware city normalization, exact city matching, DrivingConstraints parameter propagation - IAP: unknown subscription states → expired, unverified transaction logging, entitlements updated before paywall dismiss, restore visible to all users - Security: API key to Info.plist lookup, filename sanitization in PDF export, honest User-Agent, removed stale "Feels" analytics super properties - Navigation: consolidated competing navigationDestination, boolean → value-based - Testing: 8 sleep() → waitForExistence, duplicates extracted, Swift 6 compat - Service bugs: infinite retry cap, duplicate achievement prevention, TOCTOU vote fix, PollVote.odg → voterId rename, deterministic placeholder IDs, parallel MKDirections, Sendable-safe POI struct Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -233,18 +233,19 @@ enum TravelEstimator {
|
||||
/// - Parameters:
|
||||
/// - departure: Departure date/time
|
||||
/// - drivingHours: Total driving hours
|
||||
/// - drivingConstraints: Optional driving constraints to determine max daily hours (defaults to 8.0)
|
||||
/// - Returns: Array of calendar days (start of day) that travel spans
|
||||
///
|
||||
/// - Expected Behavior:
|
||||
/// - 0 hours → [departure day]
|
||||
/// - 1-8 hours → [departure day] (1 day)
|
||||
/// - 8.01-16 hours → [departure day, next day] (2 days)
|
||||
/// - 16.01-24 hours → [departure day, +1, +2] (3 days)
|
||||
/// - 1-maxDaily hours → [departure day] (1 day)
|
||||
/// - maxDaily+0.01 to 2*maxDaily hours → [departure day, next day] (2 days)
|
||||
/// - All dates are normalized to start of day (midnight)
|
||||
/// - Assumes 8 driving hours per day max
|
||||
/// - Uses maxDailyDrivingHours from constraints when provided
|
||||
static func calculateTravelDays(
|
||||
departure: Date,
|
||||
drivingHours: Double
|
||||
drivingHours: Double,
|
||||
drivingConstraints: DrivingConstraints? = nil
|
||||
) -> [Date] {
|
||||
var days: [Date] = []
|
||||
let calendar = Calendar.current
|
||||
@@ -252,8 +253,9 @@ enum TravelEstimator {
|
||||
let startDay = calendar.startOfDay(for: departure)
|
||||
days.append(startDay)
|
||||
|
||||
// Add days if driving takes multiple days (8 hrs/day max)
|
||||
let daysOfDriving = max(1, Int(ceil(drivingHours / 8.0)))
|
||||
// Use max daily hours from constraints, defaulting to 8.0
|
||||
let maxDailyHours = drivingConstraints?.maxDailyDrivingHours ?? 8.0
|
||||
let daysOfDriving = max(1, Int(ceil(drivingHours / maxDailyHours)))
|
||||
for dayOffset in 1..<daysOfDriving {
|
||||
if let nextDay = calendar.date(byAdding: .day, value: dayOffset, to: startDay) {
|
||||
days.append(nextDay)
|
||||
|
||||
Reference in New Issue
Block a user