-
-
Notifications
You must be signed in to change notification settings - Fork 14
commit 057d32e
abduznik edited this page May 23, 2026
·
1 revision
Commit: 057d32ea5bdcef6a48ceeb14e2aafb07a6a9bb3c
Author: abduznik
Date: 2026-04-28
Why: Performance or storage optimization.
lib/core/save/background_sync_queue.dart | 26 ++++++++++++++++++++++++--
lib/core/save/backup_repository.dart | 2 +-
2 files changed, 25 insertions(+), 3 deletions(-)
lib/core/save/background_sync_queue.dartlib/core/save/backup_repository.dart
diff --git a/lib/core/save/background_sync_queue.dart b/lib/core/save/background_sync_queue.dart
index 15537c5..084363d 100644
--- a/lib/core/save/background_sync_queue.dart
+++ b/lib/core/save/background_sync_queue.dart
@@ -2,6 +2,7 @@ import 'dart:io' as io;
import 'package:flutter/material.dart';
import '../romm/romm_service.dart';
import 'backup_repository.dart';
+import 'backup_entry.dart';
import '../../main.dart' show scaffoldMessengerKey;
@@ -22,8 +23,29 @@ class BackgroundSyncQueue {
return;
}
- final pending = backupRepo.getUnsyncedEntries();
- debugPrint('[BackgroundSyncQueue] Sweep complete. Found ${pending.length} pending jobs.');
+ final rawPending = backupRepo.getUnsyncedEntries();
+
+ // Group by romId and only keep the newest entry for each game to be efficient
+ final Map<String, ({String romId, BackupEntry entry})> newestPerGame = {};
+ for (final item in rawPending) {
+ final existing = newestPerGame[item.romId];
+ if (existing == null || item.entry.timestamp.isAfter(existing.entry.timestamp)) {
+ newestPerGame[item.romId] = item;
+ }
+ }
+
+ final pending = newestPerGame.values.toList();
+ // Sort oldest game first to maintain chronological order across different games
+ pending.sort((a, b) => a.entry.timestamp.compareTo(b.entry.timestamp));
+
+ // Mark skipped entries as synced so they don't stay in the queue
+ for (final item in rawPending) {
+ if (!pending.contains(item)) {
+ await backupRepo.markAsSynced(item.romId, item.entry);
+ }
+ }
+
+ debugPrint('[BackgroundSyncQueue] Sweep complete. Found ${rawPending.length} pending, consolidated to ${pending.length} unique game uploads.');
if (pending.isEmpty) return;
_isRunning = true;
diff --git a/lib/core/save/backup_repository.dart b/lib/core/save/backup_repository.dart
index ac40090..430f430 100644
--- a/lib/core/save/backup_repository.dart
+++ b/lib/core/save/backup_repository.dart
@@ -8,7 +8,7 @@ import 'backup_entry.dart';
/// so that providers stay thin.
class BackupRepository {
static const String _boxName = 'freegosy_backups';
- static const int _maxBackups = 8;
+ static const int _maxBackups = 4;
Box<List>? _box;