mirror of
https://github.com/M66B/FairEmail.git
synced 2025-03-11 14:47:11 +00:00
Retry loading initial page
This commit is contained in:
parent
2a2a7159c9
commit
ee3b6df16d
2 changed files with 112 additions and 20 deletions
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
81
patches/LimitOffsetDataSource.patch
Normal file
81
patches/LimitOffsetDataSource.patch
Normal file
|
@ -0,0 +1,81 @@
|
|||
--- /home/marcel/support/room/runtime/src/main/java/androidx/room/paging/LimitOffsetDataSource.java 2020-05-18 15:59:35.380887546 +0200
|
||||
+++ /home/marcel/email/app/src/main/java/androidx/room/paging/LimitOffsetDataSource.java 2020-06-15 15:44:12.388117961 +0200
|
||||
@@ -20,6 +20,7 @@ import android.database.Cursor;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.RestrictTo;
|
||||
+import androidx.paging.PositionalDataSource;
|
||||
import androidx.room.InvalidationTracker;
|
||||
import androidx.room.RoomDatabase;
|
||||
import androidx.room.RoomSQLiteQuery;
|
||||
@@ -42,9 +43,8 @@ import java.util.Set;
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
-@SuppressWarnings("deprecation")
|
||||
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP_PREFIX)
|
||||
-public abstract class LimitOffsetDataSource<T> extends androidx.paging.PositionalDataSource<T> {
|
||||
+public abstract class LimitOffsetDataSource<T> extends PositionalDataSource<T> {
|
||||
private final RoomSQLiteQuery mSourceQuery;
|
||||
private final String mCountQuery;
|
||||
private final String mLimitOffsetQuery;
|
||||
@@ -114,27 +114,38 @@ public abstract class LimitOffsetDataSou
|
||||
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);
|
||||
-
|
||||
- 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();
|
||||
+ 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;
|
||||
+ }
|
||||
+ } 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();
|
||||
+ }
|
||||
}
|
||||
}
|
||||
|
Loading…
Add table
Reference in a new issue