Message, channel and route histories move from whole-blob preferences to indexed SQLite rows on native platforms, so chats page from storage instead of loading a full conversation. Web keeps the preferences store. Existing histories are imported once on the first launch. Linux and Windows keep the map tile index in SQLite and import the old JSON index on first use. Unreadable legacy data no longer blocks saves, migrations or startup: it is left in place and skipped. If the database cannot be opened, the run keeps histories in preferences and the next launch merges them in. Also adds a performance profiling reference and a script that clears the Dart HTTP profile.
38 lines
1.1 KiB
Dart
38 lines
1.1 KiB
Dart
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
import 'history_store.dart';
|
|
|
|
/// Singleton wrapper for SharedPreferences to avoid redundant getInstance() calls.
|
|
///
|
|
/// BEFORE: Every storage operation called SharedPreferences.getInstance()
|
|
/// AFTER: Single getInstance() on app startup, reused throughout lifecycle
|
|
///
|
|
/// This eliminates 30+ redundant platform channel calls across the app.
|
|
class PrefsManager {
|
|
PrefsManager._();
|
|
|
|
static SharedPreferences? _instance;
|
|
|
|
/// Initialize the cached instance. Call this once during app startup in main().
|
|
static Future<void> initialize() async {
|
|
_instance ??= await SharedPreferences.getInstance();
|
|
}
|
|
|
|
/// Get the cached SharedPreferences instance.
|
|
/// Throws StateError if initialize() hasn't been called.
|
|
static SharedPreferences get instance {
|
|
if (_instance == null) {
|
|
throw StateError(
|
|
'PrefsManager not initialized. Call PrefsManager.initialize() in main() before use.',
|
|
);
|
|
}
|
|
return _instance!;
|
|
}
|
|
|
|
/// For testing: reset the instance
|
|
static void reset() {
|
|
_instance = null;
|
|
HistoryStore.reset();
|
|
}
|
|
}
|