π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mobile] Recover Magic Search after failed queries
laurenspriema18c4f023492
diff --git a/mobile/apps/photos/changes/magic-search-error-recovery.md b/mobile/apps/photos/changes/magic-search-error-recovery.mdnew file mode 100644index 0000000000..c376bb01fd--- /dev/null+++ b/mobile/apps/photos/changes/magic-search-error-recovery.md@@ -0,0 +1 @@+- Fixed Magic Search getting stuck after a failed search.diff --git a/mobile/apps/photos/lib/services/machine_learning/semantic_search/semantic_search_service.dart b/mobile/apps/photos/lib/services/machine_learning/semantic_search/semantic_search_service.dartindex 89757b202b..8cdb2f9981 100644--- a/mobile/apps/photos/lib/services/machine_learning/semantic_search/semantic_search_service.dart+++ b/mobile/apps/photos/lib/services/machine_learning/semantic_search/semantic_search_service.dart@@ -144,18 +144,27 @@ class SemanticSearchService {if (_searchScreenRequest != null) {_latestPendingQuery = query;return _searchScreenRequest!;- } else {- _searchScreenRequest = getMatchingFiles(query).then((result) {- _searchScreenRequest = null;- if (_latestPendingQuery != null) {- final String newQuery = _latestPendingQuery!;- _latestPendingQuery = null;- return searchScreenQuery(newQuery);- }+ }+ _searchScreenRequest = _runSearchScreenQuery(query);+ return _searchScreenRequest!;+ }++ Future<(String, List<EnteFile>)> _runSearchScreenQuery(String query) async {+ try {+ final result = await getMatchingFiles(query);+ if (_latestPendingQuery == null) {return (query, result);- });- return _searchScreenRequest!;+ }+ } catch (_) {+ if (_latestPendingQuery == null) {+ rethrow;+ }+ } finally {+ _searchScreenRequest = null;}+ final newQuery = _latestPendingQuery!;+ _latestPendingQuery = null;+ return searchScreenQuery(newQuery);}Future<void> clearIndexes() async {@@ -202,8 +211,9 @@ class SemanticSearchService {bool showThreshold = false;if (query.startsWith(RegExp(r"0\.\d+"))) {final parts = query.split(" ");- if (parts.length > 1) {- similarityThreshold = double.parse(parts[0]);+ final threshold = double.tryParse(parts[0]);+ if (parts.length > 1 && threshold != null) {+ similarityThreshold = threshold;query = parts.sublist(1).join(" ");showThreshold = true;}