attempt to fix test txs 2
This commit is contained in:
@@ -274,23 +274,42 @@ class SyncController extends ChangeNotifier {
|
||||
_armPushDebounce();
|
||||
}
|
||||
|
||||
/// Removes tombstoned bank txs from PocketBase before pull/push can resurrect them.
|
||||
/// Pull shared delete tombstones, then remove matching local bank rows.
|
||||
Future<void> _pullAndApplyTxDeletes(PbSyncService service) async {
|
||||
try {
|
||||
final remote = await service.pullTxDeletes(onStatus: _setStatus);
|
||||
await _bank.applyRemoteDeletes(remote, notify: false);
|
||||
} catch (error) {
|
||||
debugPrint('SyncController: tx_deletes pull skipped ($error)');
|
||||
}
|
||||
}
|
||||
|
||||
/// Removes tombstoned bank txs from the transactions collection.
|
||||
///
|
||||
/// Tombstones themselves stay local + synced via `tx_deletes` so other
|
||||
/// devices learn about the delete and do not push the row back.
|
||||
Future<void> _flushPendingTxDeletes(PbSyncService service) async {
|
||||
final pending = List<BankTransaction>.of(_bank.pendingRemoteDeletes);
|
||||
if (pending.isEmpty) return;
|
||||
_setStatus('Removing deleted bank txs…');
|
||||
try {
|
||||
final matched = await service.deleteTransactionsMatching(pending);
|
||||
if (matched.isNotEmpty) {
|
||||
_bank.clearRemoteDeletesMatching(matched);
|
||||
}
|
||||
// Do NOT clear unmatched tombstones — they still block pull resurrection
|
||||
// until pushTransactions GC removes the remote rows.
|
||||
await service.deleteTransactionsMatching(pending);
|
||||
// Keep tombstones — they must remain until every device has seen them.
|
||||
} catch (error) {
|
||||
debugPrint('SyncController: tx deletes failed ($error)');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _pushTxDeletes(PbSyncService service) async {
|
||||
final tombs = List<BankTransaction>.of(_bank.pendingRemoteDeletes);
|
||||
if (tombs.isEmpty) return;
|
||||
try {
|
||||
await service.pushTxDeletes(tombs, onStatus: _setStatus);
|
||||
} catch (error) {
|
||||
debugPrint('SyncController: tx_deletes push skipped ($error)');
|
||||
}
|
||||
}
|
||||
|
||||
void _armPushDebounce() {
|
||||
if (!_auth.isLoggedIn) return;
|
||||
if (_syncing) {
|
||||
@@ -323,7 +342,8 @@ class SyncController extends ChangeNotifier {
|
||||
|
||||
try {
|
||||
final service = PbSyncService(_auth.client);
|
||||
// Delete first — otherwise pull re-merges the row and push recreates it.
|
||||
// Learn deletes from other devices before merging bank txs / pushing.
|
||||
await _pullAndApplyTxDeletes(service);
|
||||
await _flushPendingTxDeletes(service);
|
||||
final remoteMeta = await service.pull(
|
||||
onProgress: (p) {
|
||||
@@ -438,6 +458,7 @@ class SyncController extends ChangeNotifier {
|
||||
}
|
||||
// Retry deletes in case any were queued during the pull/merge window.
|
||||
await _flushPendingTxDeletes(service);
|
||||
await _pushTxDeletes(service);
|
||||
_pushBankPending = false;
|
||||
final tombs = List<BankTransaction>.of(_bank.pendingRemoteDeletes);
|
||||
final bankSummary = await service.pushTransactions(
|
||||
@@ -448,8 +469,6 @@ class SyncController extends ChangeNotifier {
|
||||
onProgress: _setProgress,
|
||||
onStatus: _setStatus,
|
||||
);
|
||||
// Push GC removes orphan admin test rows; tombstones are done.
|
||||
_bank.clearAllPendingRemoteDeletes();
|
||||
_lastSyncedAt = DateTime.now();
|
||||
_lastError = null;
|
||||
_lastSyncSummary = '$metaSummary\n$bankSummary';
|
||||
@@ -601,7 +620,10 @@ class SyncController extends ChangeNotifier {
|
||||
}
|
||||
if (pushBank) {
|
||||
_setStatus('Updating bank txs…');
|
||||
// Other devices may have deleted test txs — learn that before push.
|
||||
await _pullAndApplyTxDeletes(service);
|
||||
await _flushPendingTxDeletes(service);
|
||||
await _pushTxDeletes(service);
|
||||
try {
|
||||
final tombs = List<BankTransaction>.of(_bank.pendingRemoteDeletes);
|
||||
final summary = await service.pushTransactions(
|
||||
@@ -612,7 +634,6 @@ class SyncController extends ChangeNotifier {
|
||||
onProgress: _setProgress,
|
||||
onStatus: _setStatus,
|
||||
);
|
||||
_bank.clearAllPendingRemoteDeletes();
|
||||
parts.add(summary);
|
||||
} catch (error) {
|
||||
debugPrint('SyncController: bank tx push skipped ($error)');
|
||||
|
||||
Reference in New Issue
Block a user