Add more logs for offline to online import

This commit is contained in:
Neeraj Gupta 2023-09-05 13:34:04 +05:30
parent 5d0007d749
commit 3c25216116
3 changed files with 27 additions and 13 deletions

View file

@ -98,22 +98,37 @@ class CodeStore {
}
_logger.info('starting offline imports');
List<Code> offlineCodes =
await CodeStore.instance.getAllCodes(accountMode: AccountMode.offline);
if(offlineCodes.isEmpty) {
List<Code> offlineCodes = await CodeStore.instance
.getAllCodes(accountMode: AccountMode.offline);
if (offlineCodes.isEmpty) {
return;
}
bool isOnlineSyncDone = await AuthenticatorService.instance.onlineSync();
if(!isOnlineSyncDone) {
debugPrint("Skipping offline import since online sync failed");
if (!isOnlineSyncDone) {
_logger.info("Skipping offline import since online sync failed");
return;
}
final List<Code> onlineCodes =
await CodeStore.instance.getAllCodes(accountMode: AccountMode.online);
_logger.info(
'Starting import of ${offlineCodes.length} offline codes when online codes are ${onlineCodes.length}',
);
for (Code eachCode in offlineCodes) {
await CodeStore.instance.addCode(
eachCode,
accountMode: AccountMode.online,
shouldSync: false,
_logger
.info('importing offline code with genID ${eachCode.generatedID}');
bool alreadyPresent = onlineCodes.any(
(oc) =>
oc.issuer == eachCode.issuer &&
oc.account == eachCode.account &&
oc.secret == eachCode.secret,
);
if (!alreadyPresent) {
await CodeStore.instance.addCode(
eachCode,
accountMode: AccountMode.online,
shouldSync: false,
);
}
await OfflineAuthenticatorDB.instance.deleteByIDs(
generatedIDs: [eachCode.generatedID!],
);

View file

@ -66,10 +66,9 @@ class _HomePageState extends State<HomePage> {
});
_initDeepLinks();
Future.delayed(
const Duration(seconds: 0),
() => CodeStore.instance.importOfflineCodes(),
const Duration(seconds: 1),
() async => await CodeStore.instance.importOfflineCodes(),
);
}
void _loadCodes() {

View file

@ -1,6 +1,6 @@
name: ente_auth
description: ente two-factor authenticator
version: 1.0.57+57
version: 1.0.58+58
publish_to: none
environment: