perf(learn): flashcards moved in the card browser go at once, in one write

Moving the chosen cards to another studyset wrote them one at a time,
each looking up its privacy keys and writing its row, while the
browser still showed them. CardBrowserBloc now shows the move at once
(gone from here, or after the cards of the studyset they go into where
the browser shows it, _withMoves) and puts them back where the move
fails, counting the failure for the screen's snack bar
(moveFailures, cardBrowserMoveFailed).

CardRepository.moveTo hands the gateway every card's new position at
once (CardGateway.updateStudysets): SyncCardGateway reads them in one
query, checks every card's key before changing any (one private card
among them refuses the whole move, as before for each), rekeys those
that need it, and updates every row in one write and one sync request.
updateStudyset delegates to it.

Whats-New: Flashcards moved to another studyset in the card browser move at once.
Whats-New-De: Im Karteikarten-Browser in ein anderes Lernset verschobene Karteikarten sind sofort dort.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
This commit is contained in:
Tizian 「ティツィアーン」 2026-11-07 23:19:20 +01:00
commit d6b2bec113
Signed by: raisondetredev
GPG key ID: 07F6FCF405488B64

View file

@ -135,12 +135,38 @@ class FakeCardGateway() implements CardGateway {
return revision.id;
}
/// When set, moving cards fails with it, none moved.
Exception? failMoves;
/// While set, moving cards waits for it to complete.
Completer<void>? holdMoves;
/// How many times cards were moved, however many at once.
int moves = 0;
@override
Future<void> updateStudysets(
String studysetId,
Map<String, String> positions,
) async {
await holdMoves?.future;
if (failMoves case final error?) {
throw error;
}
moves++;
for (final MapEntry(key: id, value: position) in positions.entries) {
_place(id, studysetId, position);
}
}
@override
Future<void> updateStudyset(
String cardId,
String studysetId,
String position,
) async {
) async => _place(cardId, studysetId, position);
void _place(String cardId, String studysetId, String position) {
if (_cards[cardId] case final card?) {
_cards[cardId] = (
studysetId: studysetId,