Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Drop Search location cache

Neeraj Guptaa40aca2f53a0
diff --git a/mobile/apps/photos/lib/services/search_service.dart b/mobile/apps/photos/lib/services/search_service.dart
index 6a40619f02..145fd1eb6d 100644
--- a/mobile/apps/photos/lib/services/search_service.dart
+++ b/mobile/apps/photos/lib/services/search_service.dart
@@ -71,7 +71,6 @@ 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;
@@ -94,7 +93,6 @@ class SearchService {
// Invalidate only; reload on demand.
_cachedFilesFuture = null;
_cachedFilesForSearch = null;
- _cachedFilesWithLocationForSearch = null;
_cachedFilesForHierarchicalSearch = null;
_cachedFilesForGenericGallery = null;
_cachedFilesForOfflineGallery = null;
@@ -297,13 +295,6 @@ 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;
@@ -443,7 +434,6 @@ class SearchService {
void clearCache() {
_cachedFilesFuture = null;
_cachedFilesForSearch = null;
- _cachedFilesWithLocationForSearch = null;
_cachedFilesForHierarchicalSearch = null;
_cachedFilesForGenericGallery = null;
_cachedFilesForOfflineGallery = null;
@@ -1003,20 +993,21 @@ class SearchService {
result[tag] = [];
}
}
- 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);
+ 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);
+ }
}
}
}
if (showNoLocation) {
- final allFiles = await getAllFilesForSearch();
final noLocationFiles = allFiles.where((file) {
return file.isOwner && !file.hasLocation;
}).toList();
@@ -1039,7 +1030,10 @@ class SearchService {
}
if (showNoLocationTag) {
_logger.info("finding photos with no location tag");
- final noLocationTagFiles = filesWithLocation.where((file) {
+ final noLocationTagFiles = allFiles.where((file) {
+ if (!file.hasLocation) {
+ return false;
+ }
for (LocalEntity<LocationTag> tag in locationTagEntities) {
if (isFileInsideLocationTag(
tag.item.centerPoint,
@@ -1100,10 +1094,7 @@ class SearchService {
if (allCitiesSearch) {
query = '';
}
- final results = await locationService.getFilesInCity(
- filesWithLocation,
- query,
- );
+ final results = await locationService.getFilesInCity(allFiles, query);
final List<City> sortedByResultCount = results.keys.toList()
..sort((a, b) => results[b]!.length.compareTo(results[a]!.length));
for (final city in sortedByResultCount) {
@@ -1564,7 +1555,7 @@ class SearchService {
final Map<LocalEntity<LocationTag>, List<EnteFile>> tagToItemsMap = {};
final List<GenericSearchResult> tagSearchResults = [];
final locationTagEntities = (await locationService.getLocationTags());
- final filesWithLocation = await getFilesWithLocationForSearch();
+ final allFiles = await getAllFilesForSearch();
final List<EnteFile> filesWithNoLocTag = [];
for (int i = 0; i < locationTagEntities.length; i++) {
@@ -1572,20 +1563,22 @@ class SearchService {
tagToItemsMap[locationTagEntities.elementAt(i)] = [];
}
- 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);
+ 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);
}
- }
- if (!hasLocationTag) {
- filesWithNoLocTag.add(file);
}
}
diff --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.dart
index 4382722f17..b9f5f7adab 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,8 +343,7 @@ class _InfoMapState extends State<InfoMap> {
.push(
MaterialPageRoute(
builder: (context) => MapScreen(
- filesFutureFn:
- SearchService.instance.getFilesWithLocationForSearch,
+ filesFutureFn: SearchService.instance.getAllFilesForSearch,
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.dart
index 82e36e2175..d12a89aec1 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.getFilesWithLocationForSearch,
+ filesFutureFn: SearchService.instance.getAllFilesForSearch,
),
),
),