fix pull ab twice in log (#11699)

The reason for calling `pullAb` twice is that when `pullAb` is called for the first time, `setCurrentName` is also called. In `setCurrentName`, if the current address book has not been initialized, it will also attempt to pull. Because `quiet` is false during the first call and `setCurrentName` is not `await` synchronously, the `abLoading` can prevent the two calls. However, `abLoading` depends on `quiet`, so we need to add a new variable `_abLoadingLock`.

Signed-off-by: 21pages <sunboeasy@gmail.com>
This commit is contained in:
21pages 2025-05-10 21:40:55 +08:00 committed by GitHub
parent 1a8e3005cd
commit 9dbb6217f7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -775,7 +775,10 @@ abstract class BaseAb {
final pullError = "".obs;
final pushError = "".obs;
final abLoading = false.obs;
final abLoading = false
.obs; // Indicates whether the UI should show a loading state for the address book.
var abPulling =
false; // Tracks whether a pull operation is currently in progress to prevent concurrent pulls. Unlike abLoading, this is not tied to UI updates.
bool initialized = false;
String name();
@ -790,17 +793,22 @@ abstract class BaseAb {
}
Future<void> pullAb({quiet = false}) async {
debugPrint("pull ab \"${name()}\"");
if (abLoading.value) return;
if (abPulling) return;
abPulling = true;
if (!quiet) {
abLoading.value = true;
pullError.value = "";
}
initialized = false;
debugPrint("pull ab \"${name()}\"");
try {
initialized = await pullAbImpl(quiet: quiet);
} catch (_) {}
} catch (e) {
debugPrint("Error occurred while pulling address book: $e");
} finally {
abLoading.value = false;
abPulling = false;
}
}
Future<bool> pullAbImpl({quiet = false});