Wrap a few things trying to prevent UI / main thread hang we saw one time

This commit is contained in:
stopflock
2025-11-08 13:23:35 -06:00
parent ca049033e4
commit 4ccf3cace3
3 changed files with 12 additions and 6 deletions

View File

@@ -150,7 +150,7 @@ Future<List<OsmNode>> _fetchSingleOverpassQuery({
return [];
}
final data = jsonDecode(response.body) as Map<String, dynamic>;
final data = await compute(jsonDecode, response.body) as Map<String, dynamic>;
final elements = data['elements'] as List<dynamic>;
if (elements.length > 20) {

View File

@@ -11,6 +11,7 @@ class NodeCache {
final Map<int, OsmNode> _nodes = {};
/// Add or update a batch of nodes in the cache.
/// TODO: Consider moving to compute() if cache operations cause ANR
void addOrUpdate(List<OsmNode> nodes) {
for (var node in nodes) {
final existing = _nodes[node.id];

View File

@@ -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<List<dynamic>> _parseCSV(String csvBody) {
return const CsvToListConverter(
fieldDelimiter: ',',
textDelimiter: '"',
eol: '\n',
).convert(csvBody);
}