Skip to content

armgit / ente

Public Imported from GitHub
0

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

Prevent infinite loops

ashilknb44ef9f68adc
diff --git a/mobile/lib/services/album_home_widget_service.dart b/mobile/lib/services/album_home_widget_service.dart
index 056b6f19b1..652f99de27 100644
--- a/mobile/lib/services/album_home_widget_service.dart
+++ b/mobile/lib/services/album_home_widget_service.dart
@@ -397,17 +397,21 @@ class AlbumHomeWidgetService {
final currentTotal = await _getTotalAlbums();
_logger.info("Current total albums in widget: $currentTotal");
- int renderedCount = 0;
-
final bool isWidgetPresent = await countHomeWidgets() > 0;
+
final limit = isWidgetPresent ? MAX_ALBUMS_LIMIT : 5;
+ final maxAttempts = limit * 10;
+
+ int renderedCount = 0;
+ int attemptsCount = 0;
+
await updateAlbumsStatus(WidgetStatus.notSynced);
final albumsWithFilesLength = albumsWithFiles.length;
final albumsWithFilesEntries = albumsWithFiles.entries.toList();
final random = Random();
- while (renderedCount < limit) {
+ while (renderedCount < limit && attemptsCount < maxAttempts) {
final randomEntry =
albumsWithFilesEntries[random.nextInt(albumsWithFilesLength)];
final randomAlbumFile = randomEntry.value.$2.elementAt(
@@ -447,6 +451,14 @@ class AlbumHomeWidgetService {
renderedCount++;
}
+
+ attemptsCount++;
+ }
+
+ if (attemptsCount >= maxAttempts) {
+ _logger.warning(
+ "Hit max attempts $maxAttempts. Only rendered $renderedCount of limit $limit.",
+ );
}
// Update the hash to track changes
diff --git a/mobile/lib/services/memory_home_widget_service.dart b/mobile/lib/services/memory_home_widget_service.dart
index 5a0e96732d..4e6e2ab9b3 100644
--- a/mobile/lib/services/memory_home_widget_service.dart
+++ b/mobile/lib/services/memory_home_widget_service.dart
@@ -303,17 +303,21 @@ class MemoryHomeWidgetService {
final currentTotal = await _getTotalMemories();
_logger.info("Current total memories in widget: $currentTotal");
- int renderedCount = 0;
-
final bool isWidgetPresent = await countHomeWidgets() > 0;
+
final limit = isWidgetPresent ? MAX_MEMORIES_LIMIT : 5;
+ final maxAttempts = limit * 10;
+
+ int renderedCount = 0;
+ int attemptsCount = 0;
+
await updateMemoriesStatus(WidgetStatus.notSynced);
final memoriesWithFilesLength = memoriesWithFiles.length;
final memoriesWithFilesEntries = memoriesWithFiles.entries.toList();
final random = Random();
- while (renderedCount < limit) {
+ while (renderedCount < limit && attemptsCount < maxAttempts) {
final randomEntry =
memoriesWithFilesEntries[random.nextInt(memoriesWithFilesLength)];
final randomMemoryFile = randomEntry.value.elementAt(
@@ -351,6 +355,14 @@ class MemoryHomeWidgetService {
renderedCount++;
}
+
+ attemptsCount++;
+ }
+
+ if (attemptsCount >= maxAttempts) {
+ _logger.warning(
+ "Hit max attempts $maxAttempts. Only rendered $renderedCount of limit $limit.",
+ );
}
if (renderedCount == 0) {
diff --git a/mobile/lib/services/people_home_widget_service.dart b/mobile/lib/services/people_home_widget_service.dart
index 02d7afd414..6b13ce0df6 100644
--- a/mobile/lib/services/people_home_widget_service.dart
+++ b/mobile/lib/services/people_home_widget_service.dart
@@ -376,17 +376,21 @@ class PeopleHomeWidgetService {
final currentTotal = await _getTotalPeople();
_logger.info("Current total people in widget: $currentTotal");
- int renderedCount = 0;
-
final bool isWidgetPresent = await countHomeWidgets() > 0;
+
final limit = isWidgetPresent ? MAX_PEOPLE_LIMIT : 5;
+ final maxAttempts = limit * 10;
+
+ int renderedCount = 0;
+ int attemptsCount = 0;
+
await updatePeopleStatus(WidgetStatus.notSynced);
final peopleWithFilesLength = peopleWithFiles.length;
final peopleWithFilesEntries = peopleWithFiles.entries.toList();
final random = Random();
- while (renderedCount < limit) {
+ while (renderedCount < limit && attemptsCount < maxAttempts) {
final randomEntry =
peopleWithFilesEntries[random.nextInt(peopleWithFilesLength)];
final randomPersonFile = randomEntry.value.$2.elementAt(
@@ -425,6 +429,14 @@ class PeopleHomeWidgetService {
renderedCount++;
}
+
+ attemptsCount++;
+ }
+
+ if (attemptsCount >= maxAttempts) {
+ _logger.warning(
+ "Hit max attempts $maxAttempts. Only rendered $renderedCount of limit $limit.",
+ );
}
if (renderedCount == 0) {