π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Reuse Search location files
Neeraj Gupta5cc713ee6cfb
diff --git a/mobile/apps/photos/lib/services/search_service.dart b/mobile/apps/photos/lib/services/search_service.dartindex 145fd1eb6d..6a40619f02 100644--- a/mobile/apps/photos/lib/services/search_service.dart+++ b/mobile/apps/photos/lib/services/search_service.dart@@ -71,6 +71,7 @@ import "package:photos/utils/people_sort_util.dart";class SearchService {Future<List<EnteFile>>? _cachedFilesFuture;Future<List<EnteFile>>? _cachedFilesForSearch;+ Future<List<EnteFile>>? _cachedFilesWithLocationForSearch;Future<List<EnteFile>>? _cachedFilesForHierarchicalSearch;Future<List<EnteFile>>? _cachedFilesForGenericGallery;Future<List<EnteFile>>? _cachedFilesForOfflineGallery;@@ -93,6 +94,7 @@ class SearchService {// Invalidate only; reload on demand._cachedFilesFuture = null;_cachedFilesForSearch = null;+ _cachedFilesWithLocationForSearch = null;_cachedFilesForHierarchicalSearch = null;_cachedFilesForGenericGallery = null;_cachedFilesForOfflineGallery = null;@@ -295,6 +297,13 @@ class SearchService {return _cachedFilesForSearch!;}+ Future<List<EnteFile>> getFilesWithLocationForSearch() {+ return _cachedFilesWithLocationForSearch ??= getAllFilesForSearch().then(+ (files) =>+ files.where((file) => file.hasLocation).toList(growable: false),+ );+ }+Future<bool> hasAnyFilesForSearch() async {if (_cachedFilesFuture != null && _cachedFilesForSearch != null) {return (await _cachedFilesForSearch!).isNotEmpty;@@ -434,6 +443,7 @@ class SearchService {void clearCache() {_cachedFilesFuture = null;_cachedFilesForSearch = null;+ _cachedFilesWithLocationForSearch = null;_cachedFilesForHierarchicalSearch = null;_cachedFilesForGenericGallery = null;_cachedFilesForOfflineGallery = null;@@ -993,21 +1003,20 @@ class SearchService {result[tag] = [];}}- final allFiles = await getAllFilesForSearch();- for (EnteFile file in allFiles) {- if (file.hasLocation) {- for (LocalEntity<LocationTag> tag in result.keys) {- if (isFileInsideLocationTag(- tag.item.centerPoint,- file.location!,- tag.item.radius,- )) {- result[tag]!.add(file);- }+ final filesWithLocation = await getFilesWithLocationForSearch();+ for (final file in filesWithLocation) {+ for (final tag in result.keys) {+ if (isFileInsideLocationTag(+ tag.item.centerPoint,+ file.location!,+ tag.item.radius,+ )) {+ result[tag]!.add(file);}}}if (showNoLocation) {+ final allFiles = await getAllFilesForSearch();final noLocationFiles = allFiles.where((file) {return file.isOwner && !file.hasLocation;}).toList();@@ -1030,10 +1039,7 @@ class SearchService {}if (showNoLocationTag) {_logger.info("finding photos with no location tag");- final noLocationTagFiles = allFiles.where((file) {- if (!file.hasLocation) {- return false;- }+ final noLocationTagFiles = filesWithLocation.where((file) {for (LocalEntity<LocationTag> tag in locationTagEntities) {if (isFileInsideLocationTag(tag.item.centerPoint,@@ -1094,7 +1100,10 @@ class SearchService {if (allCitiesSearch) {query = '';}- final results = await locationService.getFilesInCity(allFiles, query);+ final results = await locationService.getFilesInCity(+ filesWithLocation,+ query,+ );final List<City> sortedByResultCount = results.keys.toList()..sort((a, b) => results[b]!.length.compareTo(results[a]!.length));for (final city in sortedByResultCount) {@@ -1555,7 +1564,7 @@ class SearchService {final Map<LocalEntity<LocationTag>, List<EnteFile>> tagToItemsMap = {};final List<GenericSearchResult> tagSearchResults = [];final locationTagEntities = (await locationService.getLocationTags());- final allFiles = await getAllFilesForSearch();+ final filesWithLocation = await getFilesWithLocationForSearch();final List<EnteFile> filesWithNoLocTag = [];for (int i = 0; i < locationTagEntities.length; i++) {@@ -1563,23 +1572,21 @@ class SearchService {tagToItemsMap[locationTagEntities.elementAt(i)] = [];}- for (EnteFile file in allFiles) {- if (file.hasLocation) {- bool hasLocationTag = false;- for (LocalEntity<LocationTag> tag in tagToItemsMap.keys) {- if (isFileInsideLocationTag(- tag.item.centerPoint,- file.location!,- tag.item.radius,- )) {- hasLocationTag = true;- tagToItemsMap[tag]!.add(file);- }- }- if (!hasLocationTag) {- filesWithNoLocTag.add(file);+ for (final file in filesWithLocation) {+ bool hasLocationTag = false;+ for (final tag in tagToItemsMap.keys) {+ if (isFileInsideLocationTag(+ tag.item.centerPoint,+ file.location!,+ tag.item.radius,+ )) {+ hasLocationTag = true;+ tagToItemsMap[tag]!.add(file);}}+ if (!hasLocationTag) {+ filesWithNoLocTag.add(file);+ }}for (MapEntry<LocalEntity<LocationTag>, List<EnteFile>> entrydiff --git a/mobile/apps/photos/lib/ui/viewer/file_details/location_tags_widget.dart b/mobile/apps/photos/lib/ui/viewer/file_details/location_tags_widget.dartindex b9f5f7adab..4382722f17 100644--- a/mobile/apps/photos/lib/ui/viewer/file_details/location_tags_widget.dart+++ b/mobile/apps/photos/lib/ui/viewer/file_details/location_tags_widget.dart@@ -343,7 +343,8 @@ class _InfoMapState extends State<InfoMap> {.push(MaterialPageRoute(builder: (context) => MapScreen(- filesFutureFn: SearchService.instance.getAllFilesForSearch,+ filesFutureFn:+ SearchService.instance.getFilesWithLocationForSearch,center: LatLng(_fileLat, _fileLng),initialZoom: 16,),diff --git a/mobile/apps/photos/lib/ui/viewer/search/search_map_navigation.dart b/mobile/apps/photos/lib/ui/viewer/search/search_map_navigation.dartindex d12a89aec1..82e36e2175 100644--- a/mobile/apps/photos/lib/ui/viewer/search/search_map_navigation.dart+++ b/mobile/apps/photos/lib/ui/viewer/search/search_map_navigation.dart@@ -27,7 +27,7 @@ Future<void> openSearchMap(BuildContext context) async {Navigator.of(context).push(MaterialPageRoute(builder: (context) => MapScreen(- filesFutureFn: SearchService.instance.getAllFilesForSearch,+ filesFutureFn: SearchService.instance.getFilesWithLocationForSearch,),),),