fix: don't partial sync for people

This commit is contained in:
Prateek Sunal
2025-06-30 16:30:57 +05:30
parent ac8efa9d7d
commit 70faf61391
4 changed files with 13 additions and 28 deletions

View File

@@ -122,7 +122,6 @@ class AlbumHomeWidgetService {
Future<void> checkPendingAlbumsSync() async {
if (await _hasAnyBlockers()) {
_logger.warning("Widget update blocked by existing conditions");
await clearWidget();
return;
}
@@ -232,7 +231,6 @@ class AlbumHomeWidgetService {
final hasCompletedFirstImport =
LocalSyncService.instance.hasCompletedFirstImport();
if (!hasCompletedFirstImport) {
_logger.warning("First import not completed");
return true;
}
@@ -241,7 +239,6 @@ class AlbumHomeWidgetService {
final albums = getAlbumsByIds(selectedAlbumIds);
if (albums.isEmpty) {
_logger.warning("Selected albums not found");
return true;
}
@@ -263,7 +260,6 @@ class AlbumHomeWidgetService {
// Check if we have any albums selected
final selectedAlbumIds = await _getEffectiveSelectedAlbumIds();
if (selectedAlbumIds.isEmpty) {
_logger.warning("No albums selected");
return false;
}
@@ -339,10 +335,6 @@ class AlbumHomeWidgetService {
}
}
if (albumsWithFiles.isEmpty) {
_logger.warning("No albums with files found");
}
return albumsWithFiles;
}
@@ -351,7 +343,6 @@ class AlbumHomeWidgetService {
final albumsWithFiles = await _getAlbumsWithFiles();
if (albumsWithFiles.isEmpty) {
_logger.warning("No files found for any albums, clearing widget");
await clearWidget();
return;
}

View File

@@ -20,8 +20,9 @@ import "package:synchronized/synchronized.dart";
enum WidgetStatus {
// notSynced means the widget is not initialized or has no data
notSynced,
// partially synced means some widgets were updated, but not all
// partially synced means some images were synced but not all
// this can happen if some widgets were not installed but we did a sync regardless
// or if the sync fails midway
syncedPartially,
// we purposefully set widget to empty, widget had data
syncedEmpty,

View File

@@ -73,11 +73,9 @@ class MemoryHomeWidgetService {
final bool forceFetchNewMemories = await _shouldUpdateWidgetCache();
if (forceFetchNewMemories) {
_logger.info("Initializing memory widget: updating memories cache");
await _updateMemoriesWidgetCache();
await updateMemoryChanged(false);
} else {
_logger.info("Initializing memory widget: syncing existing memories");
await _refreshMemoriesWidget();
}
});
@@ -115,7 +113,6 @@ class MemoryHomeWidgetService {
Future<void> checkPendingMemorySync() async {
if (await _hasAnyBlockers()) {
_logger.warning("Widget update blocked by existing conditions");
await clearWidget();
return;
}
@@ -163,14 +160,12 @@ class MemoryHomeWidgetService {
final hasCompletedFirstImport =
LocalSyncService.instance.hasCompletedFirstImport();
if (!hasCompletedFirstImport) {
_logger.warning("First import not completed");
return true;
}
// Check if memories are enabled
final areMemoriesShown = memoriesCacheService.showAnyMemories;
if (!areMemoriesShown) {
_logger.warning("Memories not enabled");
return true;
}
@@ -266,7 +261,6 @@ class MemoryHomeWidgetService {
// TODO: Can update the method to fetch directly max limit random memories
final memoriesWithFiles = await _getMemoriesWithFiles();
if (memoriesWithFiles.isEmpty) {
_logger.warning("No memories found, clearing widget");
await clearWidget();
return;
}

View File

@@ -118,7 +118,6 @@ class PeopleHomeWidgetService {
Future<void> checkPendingPeopleSync() async {
if (await _hasAnyBlockers()) {
_logger.warning("Widget update blocked by existing conditions");
await clearWidget();
return;
}
@@ -208,25 +207,28 @@ class PeopleHomeWidgetService {
}
Future<bool> _hasAnyBlockers() async {
if (await countHomeWidgets() == 0) {
return true;
}
// Check if first import is completed
final hasCompletedFirstImport =
LocalSyncService.instance.hasCompletedFirstImport();
if (!hasCompletedFirstImport) {
_logger.warning("First import not completed");
return true;
}
// Check ML consent
if (!flagService.hasGrantedMLConsent) {
_logger.warning("ML consent not granted");
return true;
}
// Check if selected people exist
// Check if selected people or hash exist
final peopleIds = await _getEffectiveSelectedPeopleIds();
final hash = await _calculateHash(peopleIds);
if (peopleIds.isEmpty || hash.isEmpty) {
_logger.warning("No selected people found or hash is empty");
final noSelectionOrHashEmpty = peopleIds.isEmpty || hash.isEmpty;
if (noSelectionOrHashEmpty) {
return true;
}
@@ -329,9 +331,8 @@ class PeopleHomeWidgetService {
return;
}
final bool isWidgetPresent = await countHomeWidgets() > 0;
final limit = isWidgetPresent ? MAX_PEOPLE_LIMIT : 5;
final maxAttempts = limit * 10;
const limit = MAX_PEOPLE_LIMIT;
const maxAttempts = limit * 10;
int renderedCount = 0;
int attemptsCount = 0;
@@ -396,9 +397,7 @@ class PeopleHomeWidgetService {
return;
}
if (isWidgetPresent) {
await updatePeopleStatus(WidgetStatus.syncedAll);
}
await updatePeopleStatus(WidgetStatus.syncedAll);
final hash = await _calculateHash(peopleIds);
await setPeopleLastHash(hash);