From a5dc47c82d94c2af82e80eb69333385dbfc38c1f Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 11 May 2020 20:07:26 +0200 Subject: [PATCH] Fixed live data invalidation --- .../androidx/room/RoomTrackingLiveData.java | 28 +++++++----- patches/room.patch | 45 ++++++++++--------- 2 files changed, 41 insertions(+), 32 deletions(-) diff --git a/app/src/main/java/androidx/room/RoomTrackingLiveData.java b/app/src/main/java/androidx/room/RoomTrackingLiveData.java index ca595467b1..875beba9bc 100644 --- a/app/src/main/java/androidx/room/RoomTrackingLiveData.java +++ b/app/src/main/java/androidx/room/RoomTrackingLiveData.java @@ -84,19 +84,23 @@ class RoomTrackingLiveData extends LiveData { // as long as it is invalid, keep computing. try { T value = null; - int retry = 0; - while (mInvalid.compareAndSet(true, false) && !computed) { - try { - value = mComputeFunction.call(); - computed = true; - } catch (Exception e) { - if (++retry > 10) - throw new RuntimeException( - "Exception while computing database live data.", e); - eu.faircode.email.Log.w(e); + while (mInvalid.compareAndSet(true, false)) { + computed = true; + int retry = 0; + boolean done = false; + while (!done) { try { - Thread.sleep(3000L); - } catch (InterruptedException ignored) { + value = mComputeFunction.call(); + 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) { + } } } } diff --git a/patches/room.patch b/patches/room.patch index 817a79c7e2..e568d88db8 100644 --- a/patches/room.patch +++ b/patches/room.patch @@ -1,31 +1,36 @@ ---- /home/marcel/support/room/runtime/src/main/java/androidx/room/RoomTrackingLiveData.java 2019-07-27 12:47:44.950985792 +0200 -+++ app/src/main/java/androidx/room/RoomTrackingLiveData.java 2019-08-01 09:33:53.297685740 +0200 -@@ -84,13 +84,20 @@ class RoomTrackingLiveData extends Li - // as long as it is invalid, keep computing. - try { +diff --git a/home/marcel/tmp/RoomTrackingLiveData.java b/app/src/main/java/androidx/room/RoomTrackingLiveData.java +index 8df1014a4..875beba9b 100644 +--- a/home/marcel/tmp/RoomTrackingLiveData.java ++++ b/app/src/main/java/androidx/room/RoomTrackingLiveData.java +@@ -86,11 +86,22 @@ class RoomTrackingLiveData extends LiveData { T value = null; -- while (mInvalid.compareAndSet(true, false)) { -- computed = true; -+ int retry = 0; -+ while (mInvalid.compareAndSet(true, false) && !computed) { - try { - value = mComputeFunction.call(); -+ computed = true; - } catch (Exception e) { + while (mInvalid.compareAndSet(true, false)) { + computed = true; +- try { +- value = mComputeFunction.call(); +- } catch (Exception e) { - throw new RuntimeException("Exception while computing database" - + " live data.", e); -+ if (++retry > 3) -+ throw new RuntimeException( -+ "Exception while computing database live data.", e); -+ eu.faircode.email.Log.w(e); ++ int retry = 0; ++ boolean done = false; ++ while (!done) { + try { -+ Thread.sleep(3000L); -+ } catch (InterruptedException ignored) { ++ value = mComputeFunction.call(); ++ 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) { -@@ -125,6 +132,7 @@ class RoomTrackingLiveData extends Li +@@ -125,6 +136,7 @@ class RoomTrackingLiveData extends LiveData { } } };