Skip to content

armgit / ente

Public Imported from GitHub
0

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

fix incorrect use of limit in getAllFileTypesAndExtensionsResults()

ashilkn821159d57e15
diff --git a/lib/services/search_service.dart b/lib/services/search_service.dart
index 086d10db19..3787fc54b1 100644
--- a/lib/services/search_service.dart
+++ b/lib/services/search_service.dart
@@ -292,13 +292,9 @@ class SearchService {
final fileTypesAndMatchingFiles = <FileType, List<EnteFile>>{};
final extensionsAndMatchingFiles = <String, List<EnteFile>>{};
- int count = 0;
for (EnteFile file in allFiles) {
- if (limit != null && count >= limit) break;
-
if (!fileTypesAndMatchingFiles.containsKey(file.fileType)) {
fileTypesAndMatchingFiles[file.fileType] = <EnteFile>[];
- count++;
}
fileTypesAndMatchingFiles[file.fileType]!.add(file);
@@ -311,7 +307,6 @@ class SearchService {
if (ext != "") {
if (!extensionsAndMatchingFiles.containsKey(ext)) {
extensionsAndMatchingFiles[ext] = <EnteFile>[];
- count++;
}
extensionsAndMatchingFiles[ext]!.add(file);
}
@@ -327,7 +322,13 @@ class SearchService {
.add(GenericSearchResult(ResultType.fileExtension, key, value));
});
- return searchResults;
+ if (limit != null) {
+ return searchResults
+ ..shuffle()
+ ..sublist(0, limit);
+ } else {
+ return searchResults;
+ }
}
//This can be furthur optimized by not just limiting keys to 0 and 1. Use key