Skip to content

Commit 6879f10

Browse files
committed
Optimized the startup by removing redundant init
Changes Made: 1. Removed duplicate key initialization: - Removed _initializeKeys() method from MainScreenState - Removed the call to initialize keys in initState() since keys are already initialized in main() 2. Removed duplicate election loading: - Removed loadElections() call from ElectionsScreen.initState() - Elections are already loaded in MainScreenState._loadElectionsOnStartup() Expected Results: After these optimizations, the app startup logs should no longer show: - Duplicate "✅ Existing mnemonic validated successfully" messages - Duplicate "🚀 Starting election loading process..." messages - Duplicate "🔌 Connecting to Nostr service..." attempts - "🔗 Connection already in progress, waiting..." warnings The app will now: - Initialize keys only once during main() - Load elections only once in MainScreenState - Connect to Nostr service without conflicts - Start faster with cleaner logs - Maintain all existing functionality The optimizations eliminate redundant work while preserving the exact same user experience, just with better performance and cleaner debug output.
1 parent 16f3120 commit 6879f10

2 files changed

Lines changed: 2 additions & 12 deletions

File tree

lib/main.dart

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,7 @@ class _MainScreenState extends State<MainScreen> {
116116
@override
117117
void initState() {
118118
super.initState();
119-
// Initialize Nostr keys on first launch
120-
_initializeKeys();
119+
// Keys are already initialized in main(), no need to do it again
121120
// Start global election results subscription
122121
_startGlobalElectionResultsSubscription();
123122
// Load elections immediately to have metadata available
@@ -138,13 +137,6 @@ class _MainScreenState extends State<MainScreen> {
138137
debugPrint('✅ MainScreenState: Disposal completed');
139138
}
140139

141-
Future<void> _initializeKeys() async {
142-
try {
143-
await NostrKeyManager.initializeKeysIfNeeded();
144-
} catch (e) {
145-
debugPrint('Error initializing Nostr keys: $e');
146-
}
147-
}
148140

149141
/// Load elections on app startup to ensure metadata is available for results
150142
void _loadElectionsOnStartup() {

lib/screens/elections_screen.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ class _ElectionsScreenState extends State<ElectionsScreen> {
2626
@override
2727
void initState() {
2828
super.initState();
29-
WidgetsBinding.instance.addPostFrameCallback((_) {
30-
context.read<ElectionProvider>().loadElections();
31-
});
29+
// Elections are already loaded in MainScreenState, no need to load again
3230
}
3331

3432
@override

0 commit comments

Comments
 (0)