idk but it's better - cache busting works.

This commit is contained in:
stopflock
2025-08-24 19:38:42 -05:00
parent 9e620ef9e4
commit 17c9ee0c5c
7 changed files with 114 additions and 38 deletions
+7 -8
View File
@@ -79,7 +79,7 @@ class MapDataProvider {
pageSize: AppState.instance.maxCameras,
);
} catch (e) {
print('[MapDataProvider] Remote camera fetch failed, error: $e. Falling back to local.');
debugPrint('[MapDataProvider] Remote camera fetch failed, error: $e. Falling back to local.');
return fetchLocalCameras(
bounds: bounds,
profiles: profiles,
@@ -152,14 +152,13 @@ class MapDataProvider {
final selectedTileType = appState.selectedTileType;
final selectedProvider = appState.selectedTileProvider;
if (selectedTileType != null && selectedProvider != null) {
// Use current provider
final tileUrl = selectedTileType.getTileUrl(z, x, y, apiKey: selectedProvider.apiKey);
return fetchRemoteTile(z: z, x: x, y: y, url: tileUrl);
} else {
// Fallback to OSM if no provider selected
return fetchOSMTile(z: z, x: x, y: y);
// We guarantee that a provider and tile type are always selected
if (selectedTileType == null || selectedProvider == null) {
throw Exception('No tile provider selected - this should never happen');
}
final tileUrl = selectedTileType.getTileUrl(z, x, y, apiKey: selectedProvider.apiKey);
return fetchRemoteTile(z: z, x: x, y: y, url: tileUrl);
}
/// Clear any queued tile requests (call when map view changes significantly)
@@ -1,5 +1,6 @@
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:flutter/foundation.dart';
import 'package:latlong2/latlong.dart';
import 'package:flutter_map/flutter_map.dart';
@@ -43,15 +44,19 @@ Future<List<OsmCameraNode>> camerasFromOverpass({
print('[camerasFromOverpass] Querying Overpass...');
print('[camerasFromOverpass] Query:\n$query');
final resp = await http.post(Uri.parse(prodEndpoint), body: {'data': query.trim()});
print('[camerasFromOverpass] Status: ${resp.statusCode}, Length: ${resp.body.length}');
// Only log errors
if (resp.statusCode != 200) {
print('[camerasFromOverpass] Overpass failed: ${resp.body}');
debugPrint('[camerasFromOverpass] Overpass failed: ${resp.body}');
NetworkStatus.instance.reportOverpassIssue();
return [];
}
final data = jsonDecode(resp.body) as Map<String, dynamic>;
final elements = data['elements'] as List<dynamic>;
print('[camerasFromOverpass] Retrieved elements: ${elements.length}');
// Only log if many cameras found or if it's a bulk download
if (elements.length > 20 || fetchAllPages) {
debugPrint('[camerasFromOverpass] Retrieved ${elements.length} cameras');
}
NetworkStatus.instance.reportOverpassSuccess();
return elements.whereType<Map<String, dynamic>>().map((e) {
return OsmCameraNode(
@@ -12,12 +12,13 @@ final _tileFetchSemaphore = _SimpleSemaphore(4); // Max 4 concurrent
/// Clear queued tile requests when map view changes significantly
void clearRemoteTileQueue() {
final clearedCount = _tileFetchSemaphore.clearQueue();
debugPrint('[RemoteTiles] Cleared $clearedCount queued tile requests');
// Only log if we actually cleared something significant
if (clearedCount > 5) {
debugPrint('[RemoteTiles] Cleared $clearedCount queued tile requests');
}
}
/// Legacy alias for backward compatibility
@Deprecated('Use clearRemoteTileQueue instead')
void clearOSMTileQueue() => clearRemoteTileQueue();
/// Fetches a tile from any remote provider, with in-memory retries/backoff, and global concurrency limit.
/// Returns tile image bytes, or throws on persistent failure.
@@ -50,11 +51,11 @@ Future<List<int>> fetchRemoteTile({
if (resp.statusCode == 200 && resp.bodyBytes.isNotEmpty) {
// Success - no logging for normal operation
NetworkStatus.instance.reportOsmTileSuccess(); // Still use OSM reporting for now
NetworkStatus.instance.reportOsmTileSuccess(); // Generic tile server reporting
return resp.bodyBytes;
} else {
debugPrint('[fetchRemoteTile] FAIL $z/$x/$y from $hostInfo: code=${resp.statusCode}, bytes=${resp.bodyBytes.length}');
NetworkStatus.instance.reportOsmTileIssue(); // Still use OSM reporting for now
NetworkStatus.instance.reportOsmTileIssue(); // Generic tile server reporting
throw HttpException('Failed to fetch tile $z/$x/$y from $hostInfo: status ${resp.statusCode}');
}
} catch (e) {
@@ -62,7 +63,7 @@ Future<List<int>> fetchRemoteTile({
if (e.toString().contains('Connection refused') ||
e.toString().contains('Connection timed out') ||
e.toString().contains('Connection reset')) {
NetworkStatus.instance.reportOsmTileIssue(); // Still use OSM reporting for now
NetworkStatus.instance.reportOsmTileIssue(); // Generic tile server reporting
}
if (attempt >= maxAttempts) {
+7 -7
View File
@@ -44,12 +44,12 @@ class NetworkStatus extends ChangeNotifier {
return null;
}
/// Report OSM tile server issues
/// Report tile server issues (for any provider)
void reportOsmTileIssue() {
if (!_osmTilesHaveIssues) {
_osmTilesHaveIssues = true;
notifyListeners();
debugPrint('[NetworkStatus] OSM tile server issues detected');
debugPrint('[NetworkStatus] Tile server issues detected');
}
// Reset recovery timer - if we keep getting errors, keep showing indicator
@@ -57,7 +57,7 @@ class NetworkStatus extends ChangeNotifier {
_osmRecoveryTimer = Timer(const Duration(minutes: 2), () {
_osmTilesHaveIssues = false;
notifyListeners();
debugPrint('[NetworkStatus] OSM tile server issues cleared');
debugPrint('[NetworkStatus] Tile server issues cleared');
});
}
@@ -82,7 +82,7 @@ class NetworkStatus extends ChangeNotifier {
void reportOsmTileSuccess() {
// Clear issues immediately on success (they were likely temporary)
if (_osmTilesHaveIssues) {
debugPrint('[NetworkStatus] OSM tile server issues cleared after success');
// Quietly clear - don't log routine success
_osmTilesHaveIssues = false;
_osmRecoveryTimer?.cancel();
notifyListeners();
@@ -91,7 +91,7 @@ class NetworkStatus extends ChangeNotifier {
void reportOverpassSuccess() {
if (_overpassHasIssues) {
debugPrint('[NetworkStatus] Overpass API issues cleared after success');
// Quietly clear - don't log routine success
_overpassHasIssues = false;
_overpassRecoveryTimer?.cancel();
notifyListeners();
@@ -109,7 +109,7 @@ class NetworkStatus extends ChangeNotifier {
if (!_isWaitingForData) {
_isWaitingForData = true;
notifyListeners();
debugPrint('[NetworkStatus] Waiting for data...');
// Don't log routine waiting - only log if we stay waiting too long
}
// Set timeout to show appropriate status after reasonable time
@@ -140,7 +140,7 @@ class NetworkStatus extends ChangeNotifier {
_waitingTimer?.cancel();
_noDataResetTimer?.cancel();
notifyListeners();
debugPrint('[NetworkStatus] Waiting/timeout/no-data status cleared - data arrived');
// Quietly clear waiting status - don't log routine data arrival
}
}