From 4ccf3cace3a0577613ae294d270b48da7c6c5787 Mon Sep 17 00:00:00 2001 From: stopflock Date: Sat, 8 Nov 2025 13:23:35 -0600 Subject: [PATCH] Wrap a few things trying to prevent UI / main thread hang we saw one time --- .../map_data_submodules/nodes_from_overpass.dart | 2 +- lib/services/node_cache.dart | 1 + lib/services/suspected_location_service.dart | 15 ++++++++++----- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/services/map_data_submodules/nodes_from_overpass.dart b/lib/services/map_data_submodules/nodes_from_overpass.dart index d14eacc..cd24322 100644 --- a/lib/services/map_data_submodules/nodes_from_overpass.dart +++ b/lib/services/map_data_submodules/nodes_from_overpass.dart @@ -150,7 +150,7 @@ Future> _fetchSingleOverpassQuery({ return []; } - final data = jsonDecode(response.body) as Map; + final data = await compute(jsonDecode, response.body) as Map; final elements = data['elements'] as List; if (elements.length > 20) { diff --git a/lib/services/node_cache.dart b/lib/services/node_cache.dart index df781b0..92108de 100644 --- a/lib/services/node_cache.dart +++ b/lib/services/node_cache.dart @@ -11,6 +11,7 @@ class NodeCache { final Map _nodes = {}; /// Add or update a batch of nodes in the cache. + /// TODO: Consider moving to compute() if cache operations cause ANR void addOrUpdate(List nodes) { for (var node in nodes) { final existing = _nodes[node.id]; diff --git a/lib/services/suspected_location_service.dart b/lib/services/suspected_location_service.dart index 233b95a..6935749 100644 --- a/lib/services/suspected_location_service.dart +++ b/lib/services/suspected_location_service.dart @@ -120,11 +120,7 @@ class SuspectedLocationService { onProgress?.call('Parsing CSV data...', 0.2); // Parse CSV with proper field separator and quote handling - final csvData = const CsvToListConverter( - fieldDelimiter: ',', - textDelimiter: '"', - eol: '\n', - ).convert(response.body); + final csvData = await compute(_parseCSV, response.body); debugPrint('[SuspectedLocationService] Parsed ${csvData.length} rows from CSV'); if (csvData.isEmpty) { @@ -223,4 +219,13 @@ class SuspectedLocationService { LatLng(south, east), )); } +} + +/// Simple CSV parser for compute() - must be top-level function +List> _parseCSV(String csvBody) { + return const CsvToListConverter( + fieldDelimiter: ',', + textDelimiter: '"', + eol: '\n', + ).convert(csvBody); } \ No newline at end of file