concurrency work in prep for speeding things up

refactor splash screen to process initialization in a better way
more async tools for async cubit constructors
greatly improved StateMapFollower class
This commit is contained in:
Christien Rioux 2024-04-03 21:55:49 -04:00
parent 8da1dc7d32
commit 9bb20f4dd2
47 changed files with 886 additions and 579 deletions

View file

@ -3,24 +3,13 @@ import 'dart:async';
import 'package:bloc/bloc.dart';
import 'package:veilid_support/veilid_support.dart';
import '../../init.dart';
import '../repository/account_repository/account_repository.dart';
class ActiveLocalAccountCubit extends Cubit<TypedKey?> {
ActiveLocalAccountCubit(AccountRepository accountRepository)
: _accountRepository = accountRepository,
super(null) {
super(accountRepository.getActiveLocalAccount()) {
// Subscribe to streams
_initAccountRepositorySubscription();
// Initialize when we can
Future.delayed(Duration.zero, () async {
await eventualInitialized.future;
emit(_accountRepository.getActiveLocalAccount());
});
}
void _initAccountRepositorySubscription() {
_accountRepositorySubscription = _accountRepository.stream.listen((change) {
switch (change) {
case AccountRepositoryChange.activeLocalAccount:

View file

@ -3,25 +3,14 @@ import 'dart:async';
import 'package:bloc/bloc.dart';
import 'package:fast_immutable_collections/fast_immutable_collections.dart';
import '../../init.dart';
import '../models/models.dart';
import '../repository/account_repository/account_repository.dart';
class LocalAccountsCubit extends Cubit<IList<LocalAccount>> {
LocalAccountsCubit(AccountRepository accountRepository)
: _accountRepository = accountRepository,
super(IList<LocalAccount>()) {
super(accountRepository.getLocalAccounts()) {
// Subscribe to streams
_initAccountRepositorySubscription();
// Initialize when we can
Future.delayed(Duration.zero, () async {
await eventualInitialized.future;
emit(_accountRepository.getLocalAccounts());
});
}
void _initAccountRepositorySubscription() {
_accountRepositorySubscription = _accountRepository.stream.listen((change) {
switch (change) {
case AccountRepositoryChange.localAccounts:

View file

@ -3,25 +3,14 @@ import 'dart:async';
import 'package:bloc/bloc.dart';
import 'package:fast_immutable_collections/fast_immutable_collections.dart';
import '../../init.dart';
import '../models/models.dart';
import '../repository/account_repository/account_repository.dart';
class UserLoginsCubit extends Cubit<IList<UserLogin>> {
UserLoginsCubit(AccountRepository accountRepository)
: _accountRepository = accountRepository,
super(IList<UserLogin>()) {
super(accountRepository.getUserLogins()) {
// Subscribe to streams
_initAccountRepositorySubscription();
// Initialize when we can
Future.delayed(Duration.zero, () async {
await eventualInitialized.future;
emit(_accountRepository.getUserLogins());
});
}
void _initAccountRepositorySubscription() {
_accountRepositorySubscription = _accountRepository.stream.listen((change) {
switch (change) {
case AccountRepositoryChange.userLogins:

View file

@ -202,18 +202,24 @@ class AccountRepository {
createAccountCallback: (parent) async {
// Make empty contact list
log.debug('Creating contacts list');
final contactList = await (await DHTShortArray.create(parent: parent))
final contactList = await (await DHTShortArray.create(
debugName: 'AccountRepository::_newLocalAccount::Contacts',
parent: parent))
.scope((r) async => r.recordPointer);
// Make empty contact invitation record list
log.debug('Creating contact invitation records list');
final contactInvitationRecords =
await (await DHTShortArray.create(parent: parent))
.scope((r) async => r.recordPointer);
final contactInvitationRecords = await (await DHTShortArray.create(
debugName:
'AccountRepository::_newLocalAccount::ContactInvitations',
parent: parent))
.scope((r) async => r.recordPointer);
// Make empty chat record list
log.debug('Creating chat records list');
final chatRecords = await (await DHTShortArray.create(parent: parent))
final chatRecords = await (await DHTShortArray.create(
debugName: 'AccountRepository::_newLocalAccount::Chats',
parent: parent))
.scope((r) async => r.recordPointer);
// Make account object
@ -391,6 +397,7 @@ class AccountRepository {
final pool = DHTRecordPool.instance;
final record = await pool.openOwned(
userLogin.accountRecordInfo.accountRecord,
debugName: 'AccountRepository::openAccountRecord::AccountRecord',
parent: localAccount.identityMaster.identityRecordKey);
return record;