mirror of
https://github.com/FoggedLens/deflock-app.git
synced 2026-02-12 16:52:51 +00:00
Wrap a few things trying to prevent UI / main thread hang we saw one time
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user