mirror of
https://github.com/M66B/FairEmail.git
synced 2025-01-03 05:34:51 +00:00
Fixed live data invalidation
This commit is contained in:
parent
cfb0450e30
commit
a5dc47c82d
2 changed files with 41 additions and 32 deletions
|
@ -84,19 +84,23 @@ class RoomTrackingLiveData<T> extends LiveData<T> {
|
||||||
// as long as it is invalid, keep computing.
|
// as long as it is invalid, keep computing.
|
||||||
try {
|
try {
|
||||||
T value = null;
|
T value = null;
|
||||||
int retry = 0;
|
while (mInvalid.compareAndSet(true, false)) {
|
||||||
while (mInvalid.compareAndSet(true, false) && !computed) {
|
computed = true;
|
||||||
try {
|
int retry = 0;
|
||||||
value = mComputeFunction.call();
|
boolean done = false;
|
||||||
computed = true;
|
while (!done) {
|
||||||
} catch (Exception e) {
|
|
||||||
if (++retry > 10)
|
|
||||||
throw new RuntimeException(
|
|
||||||
"Exception while computing database live data.", e);
|
|
||||||
eu.faircode.email.Log.w(e);
|
|
||||||
try {
|
try {
|
||||||
Thread.sleep(3000L);
|
value = mComputeFunction.call();
|
||||||
} catch (InterruptedException ignored) {
|
done = true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (++retry > 10)
|
||||||
|
throw new RuntimeException(
|
||||||
|
"Exception while computing database live data.", e);
|
||||||
|
eu.faircode.email.Log.w(e);
|
||||||
|
try {
|
||||||
|
Thread.sleep(3000L);
|
||||||
|
} catch (InterruptedException ignored) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,31 +1,36 @@
|
||||||
--- /home/marcel/support/room/runtime/src/main/java/androidx/room/RoomTrackingLiveData.java 2019-07-27 12:47:44.950985792 +0200
|
diff --git a/home/marcel/tmp/RoomTrackingLiveData.java b/app/src/main/java/androidx/room/RoomTrackingLiveData.java
|
||||||
+++ app/src/main/java/androidx/room/RoomTrackingLiveData.java 2019-08-01 09:33:53.297685740 +0200
|
index 8df1014a4..875beba9b 100644
|
||||||
@@ -84,13 +84,20 @@ class RoomTrackingLiveData<T> extends Li
|
--- a/home/marcel/tmp/RoomTrackingLiveData.java
|
||||||
// as long as it is invalid, keep computing.
|
+++ b/app/src/main/java/androidx/room/RoomTrackingLiveData.java
|
||||||
try {
|
@@ -86,11 +86,22 @@ class RoomTrackingLiveData<T> extends LiveData<T> {
|
||||||
T value = null;
|
T value = null;
|
||||||
- while (mInvalid.compareAndSet(true, false)) {
|
while (mInvalid.compareAndSet(true, false)) {
|
||||||
- computed = true;
|
computed = true;
|
||||||
+ int retry = 0;
|
- try {
|
||||||
+ while (mInvalid.compareAndSet(true, false) && !computed) {
|
- value = mComputeFunction.call();
|
||||||
try {
|
- } catch (Exception e) {
|
||||||
value = mComputeFunction.call();
|
|
||||||
+ computed = true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
- throw new RuntimeException("Exception while computing database"
|
- throw new RuntimeException("Exception while computing database"
|
||||||
- + " live data.", e);
|
- + " live data.", e);
|
||||||
+ if (++retry > 3)
|
+ int retry = 0;
|
||||||
+ throw new RuntimeException(
|
+ boolean done = false;
|
||||||
+ "Exception while computing database live data.", e);
|
+ while (!done) {
|
||||||
+ eu.faircode.email.Log.w(e);
|
|
||||||
+ try {
|
+ try {
|
||||||
+ Thread.sleep(3000L);
|
+ value = mComputeFunction.call();
|
||||||
+ } catch (InterruptedException ignored) {
|
+ done = true;
|
||||||
|
+ } catch (Exception e) {
|
||||||
|
+ if (++retry > 10)
|
||||||
|
+ throw new RuntimeException(
|
||||||
|
+ "Exception while computing database live data.", e);
|
||||||
|
+ eu.faircode.email.Log.w(e);
|
||||||
|
+ try {
|
||||||
|
+ Thread.sleep(3000L);
|
||||||
|
+ } catch (InterruptedException ignored) {
|
||||||
|
+ }
|
||||||
+ }
|
+ }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (computed) {
|
if (computed) {
|
||||||
@@ -125,6 +132,7 @@ class RoomTrackingLiveData<T> extends Li
|
@@ -125,6 +136,7 @@ class RoomTrackingLiveData<T> extends LiveData<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue