π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
perf: offload work from main isolate of finding most recent file and generating temp markers from list of files passed to map screen to a different isolate to avoid blocking UI
ashilkn464a840a9cdd
diff --git a/lib/ui/map/map_screen.dart b/lib/ui/map/map_screen.dartindex c4d5148a4f..adb2d590d9 100644--- a/lib/ui/map/map_screen.dart+++ b/lib/ui/map/map_screen.dart@@ -2,6 +2,7 @@ import "dart:async";import "dart:isolate";import "package:collection/collection.dart";+import "package:computer/computer.dart";import "package:flutter/foundation.dart";import 'package:flutter/material.dart';import 'package:flutter_map/flutter_map.dart';@@ -79,39 +80,13 @@ class _MapScreenState extends State<MapScreen> {}Future<void> processFiles(List<EnteFile> files) async {- final List<ImageMarker> tempMarkers = [];- EnteFile? mostRecentFile;- for (var file in files) {- if (file.hasLocation) {- if (!Location.isValidRange(- latitude: file.location!.latitude!,- longitude: file.location!.longitude!,- )) {- _logger.warning(- 'Skipping file with invalid location ${file.toString()}',- );- continue;- }-- if (widget.center == null) {- if (mostRecentFile == null) {- mostRecentFile = file;- } else {- if ((mostRecentFile.creationTime ?? 0) < (file.creationTime ?? 0)) {- mostRecentFile = file;- }- }- }+ final result = await Computer.shared().compute(+ _findRecentFileAndGenerateTempMarkers,+ param: {"files": files, "center": widget.center},+ );- tempMarkers.add(- ImageMarker(- latitude: file.location!.latitude!,- longitude: file.location!.longitude!,- imageFile: file,- ),- );- }- }+ final EnteFile? mostRecentFile = result.$1;+ final List<ImageMarker> tempMarkers = result.$2;if (tempMarkers.isNotEmpty) {center = widget.center ??@@ -171,6 +146,50 @@ class _MapScreenState extends State<MapScreen> {});}+ static (EnteFile?, List<ImageMarker>) _findRecentFileAndGenerateTempMarkers(+ Map<String, dynamic> args,+ ) {+ final Logger logger = Logger("_MapScreenState");+ final files = args["files"] as List<EnteFile>;+ final center = args["center"] as LatLng?;+ final List<ImageMarker> tempMarkers = [];+ EnteFile? mostRecentFile;++ for (var file in files) {+ if (file.hasLocation) {+ if (!Location.isValidRange(+ latitude: file.location!.latitude!,+ longitude: file.location!.longitude!,+ )) {+ logger.warning(+ 'Skipping file with invalid location ${file.toString()}',+ );+ continue;+ }++ if (center == null) {+ if (mostRecentFile == null) {+ mostRecentFile = file;+ } else {+ if ((mostRecentFile.creationTime ?? 0) < (file.creationTime ?? 0)) {+ mostRecentFile = file;+ }+ }+ }++ tempMarkers.add(+ ImageMarker(+ latitude: file.location!.latitude!,+ longitude: file.location!.longitude!,+ imageFile: file,+ ),+ );+ }+ }++ return (mostRecentFile, tempMarkers);+ }+@pragma('vm:entry-point')static void _calculateMarkersIsolate(MapIsolate message) async {final bounds = message.bounds;