Ignore cache if it failed and write unit test for forceEmailQuery = true

(cherry picked from commit 05496806823b6daed2b0abd889915a5fd7d5f88f)
This commit is contained in:
dab246
2025-11-27 16:48:40 +07:00
committed by Dat H. Pham
parent 0518115566
commit f89bfaca74
2 changed files with 367 additions and 15 deletions
@@ -159,21 +159,39 @@ class ThreadRepositoryImpl extends ThreadRepository {
return;
}
// Load cached emails + cached state
final cachedList = await localDataSource.getAllEmailCache(
accountId,
session.username,
inMailboxId: emailFilter?.mailboxId,
sort: sort,
limit: limit,
filterOption: emailFilter?.filterOption,
);
List<Email> cachedList = const [];
jmap.State? cachedState;
final cachedState = await stateDataSource.getState(
accountId,
session.username,
StateType.email,
);
// Load cached emails
try {
cachedList = await localDataSource.getAllEmailCache(
accountId,
session.username,
inMailboxId: emailFilter?.mailboxId,
sort: sort,
limit: limit,
filterOption: emailFilter?.filterOption,
);
} catch (_) {
logError(
'ThreadRepositoryImpl::forceQueryAllEmailsForWeb(): '
'Failed to load cached emails',
);
}
// Load cached state
try {
cachedState = await stateDataSource.getState(
accountId,
session.username,
StateType.email,
);
} catch (_) {
logError(
'ThreadRepositoryImpl::forceQueryAllEmailsForWeb(): '
'Failed to load cached email state',
);
}
final localResponse = EmailsResponse(
emailList: cachedList,
@@ -211,7 +229,7 @@ class ThreadRepositoryImpl extends ThreadRepository {
// Combine server list + keep existing state
yield EmailsResponse(
emailList: serverResponse.emailList,
state: cachedState,
state: cachedState ?? serverResponse.state,
);
}