mirror of
https://github.com/M66B/FairEmail.git
synced 2026-01-02 19:10:11 +01:00
Retry loading initial page
This commit is contained in:
@@ -114,27 +114,38 @@ public abstract class LimitOffsetDataSource<T> extends PositionalDataSource<T> {
|
||||
int firstLoadPosition = 0;
|
||||
RoomSQLiteQuery sqLiteQuery = null;
|
||||
Cursor cursor = null;
|
||||
mDb.beginTransaction();
|
||||
try {
|
||||
totalCount = countItems();
|
||||
if (totalCount != 0) {
|
||||
// bound the size requested, based on known count
|
||||
firstLoadPosition = computeInitialLoadPosition(params, totalCount);
|
||||
int firstLoadSize = computeInitialLoadSize(params, firstLoadPosition, totalCount);
|
||||
int retry = 0;
|
||||
while (cursor == null) {
|
||||
mDb.beginTransaction();
|
||||
try {
|
||||
totalCount = countItems();
|
||||
if (totalCount != 0) {
|
||||
// bound the size requested, based on known count
|
||||
firstLoadPosition = computeInitialLoadPosition(params, totalCount);
|
||||
int firstLoadSize = computeInitialLoadSize(params, firstLoadPosition, totalCount);
|
||||
|
||||
sqLiteQuery = getSQLiteQuery(firstLoadPosition, firstLoadSize);
|
||||
cursor = mDb.query(sqLiteQuery);
|
||||
List<T> rows = convertRows(cursor);
|
||||
mDb.setTransactionSuccessful();
|
||||
list = rows;
|
||||
}
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
mDb.endTransaction();
|
||||
if (sqLiteQuery != null) {
|
||||
sqLiteQuery.release();
|
||||
sqLiteQuery = getSQLiteQuery(firstLoadPosition, firstLoadSize);
|
||||
cursor = mDb.query(sqLiteQuery);
|
||||
List<T> rows = convertRows(cursor);
|
||||
mDb.setTransactionSuccessful();
|
||||
list = rows;
|
||||
}
|
||||
} catch (Throwable ex) {
|
||||
if (++retry > 10)
|
||||
throw ex;
|
||||
eu.faircode.email.Log.w(ex);
|
||||
try {
|
||||
Thread.sleep(3000L);
|
||||
} catch (InterruptedException ignored) {
|
||||
}
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
mDb.endTransaction();
|
||||
if (sqLiteQuery != null) {
|
||||
sqLiteQuery.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user