From 9dbb6217f7c97523c4fc401ed4d8434dc709dea9 Mon Sep 17 00:00:00 2001 From: 21pages Date: Sat, 10 May 2025 21:40:55 +0800 Subject: [PATCH] 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 --- flutter/lib/models/ab_model.dart | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/flutter/lib/models/ab_model.dart b/flutter/lib/models/ab_model.dart index 5efbd9e5f..390150505 100644 --- a/flutter/lib/models/ab_model.dart +++ b/flutter/lib/models/ab_model.dart @@ -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 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 (_) {} - abLoading.value = false; + } catch (e) { + debugPrint("Error occurred while pulling address book: $e"); + } finally { + abLoading.value = false; + abPulling = false; + } } Future pullAbImpl({quiet = false});