invalidate cache including bg after bg change

This commit is contained in:
Milos Kozak 2020-06-02 19:28:56 +02:00
parent 608142cb74
commit 484f3a2a98
3 changed files with 19 additions and 5 deletions

View file

@ -52,6 +52,7 @@ import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.bus.RxBusWrapper; import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventNewHistoryBgData;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventNewHistoryData; import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventNewHistoryData;
import info.nightscout.androidaps.plugins.pump.insight.database.InsightBolusID; import info.nightscout.androidaps.plugins.pump.insight.database.InsightBolusID;
import info.nightscout.androidaps.plugins.pump.insight.database.InsightHistoryOffset; import info.nightscout.androidaps.plugins.pump.insight.database.InsightHistoryOffset;
@ -386,7 +387,8 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
old.copyFrom(bgReading); old.copyFrom(bgReading);
getDaoBgReadings().update(old); getDaoBgReadings().update(old);
aapsLogger.debug(LTag.DATABASE, "BG: Updating record from: " + from + " New data: " + old.toString()); aapsLogger.debug(LTag.DATABASE, "BG: Updating record from: " + from + " New data: " + old.toString());
scheduleBgChange(bgReading); rxBus.send(new EventNewHistoryBgData(old.date)); // trigger cache invalidation
scheduleBgChange(bgReading); // trigger new calculation
return false; return false;
} }
} catch (SQLException e) { } catch (SQLException e) {

View file

@ -39,6 +39,7 @@ import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.bus.RxBusWrapper; import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
import info.nightscout.androidaps.interfaces.ProfileFunction; import info.nightscout.androidaps.interfaces.ProfileFunction;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.data.AutosensData; import info.nightscout.androidaps.plugins.iob.iobCobCalculator.data.AutosensData;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventNewHistoryBgData;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventNewHistoryData; import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventNewHistoryData;
import info.nightscout.androidaps.plugins.sensitivity.SensitivityAAPSPlugin; import info.nightscout.androidaps.plugins.sensitivity.SensitivityAAPSPlugin;
import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref1Plugin; import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref1Plugin;
@ -159,7 +160,7 @@ public class IobCobCalculatorPlugin extends PluginBase implements IobCobCalculat
runCalculation("onNewProfile", System.currentTimeMillis(), false, true, event); runCalculation("onNewProfile", System.currentTimeMillis(), false, true, event);
}, fabricPrivacy::logException) }, fabricPrivacy::logException)
); );
// EventNewBG // EventNewBG .... cannot be used for invalidating because only event with last BG is fired
disposable.add(rxBus disposable.add(rxBus
.toObservable(EventNewBG.class) .toObservable(EventNewBG.class)
.observeOn(Schedulers.io()) .observeOn(Schedulers.io())
@ -203,7 +204,13 @@ public class IobCobCalculatorPlugin extends PluginBase implements IobCobCalculat
disposable.add(rxBus disposable.add(rxBus
.toObservable(EventNewHistoryData.class) .toObservable(EventNewHistoryData.class)
.observeOn(Schedulers.io()) .observeOn(Schedulers.io())
.subscribe(this::newHistoryData, fabricPrivacy::logException) .subscribe(event -> newHistoryData(event, false), fabricPrivacy::logException)
);
// EventNewHistoryBgData
disposable.add(rxBus
.toObservable(EventNewHistoryBgData.class)
.observeOn(Schedulers.io())
.subscribe(event -> newHistoryData(new EventNewHistoryData(event.getTimestamp()), true), fabricPrivacy::logException)
); );
} }
@ -822,7 +829,7 @@ public class IobCobCalculatorPlugin extends PluginBase implements IobCobCalculat
} }
// When historical data is changed (comming from NS etc) finished calculations after this date must be invalidated // When historical data is changed (comming from NS etc) finished calculations after this date must be invalidated
private void newHistoryData(EventNewHistoryData ev) { private void newHistoryData(EventNewHistoryData ev, boolean bgDataReload) {
//log.debug("Locking onNewHistoryData"); //log.debug("Locking onNewHistoryData");
stopCalculation("onEventNewHistoryData"); stopCalculation("onEventNewHistoryData");
synchronized (dataLock) { synchronized (dataLock) {
@ -862,7 +869,7 @@ public class IobCobCalculatorPlugin extends PluginBase implements IobCobCalculat
} }
} }
} }
runCalculation("onEventNewHistoryData", System.currentTimeMillis(), false, true, ev); runCalculation("onEventNewHistoryData", System.currentTimeMillis(), bgDataReload, true, ev);
//log.debug("Releasing onNewHistoryData"); //log.debug("Releasing onNewHistoryData");
} }

View file

@ -0,0 +1,5 @@
package info.nightscout.androidaps.plugins.iob.iobCobCalculator.events
import info.nightscout.androidaps.events.Event
class EventNewHistoryBgData(val timestamp: Long) : Event()