Use memory record for lastBg instead of DB query

This commit is contained in:
Milos Kozak 2019-02-25 20:04:29 +01:00
parent b0dd2f464b
commit 337d350ce2

View file

@ -45,7 +45,7 @@ import info.nightscout.androidaps.events.EventTempTargetChange;
import info.nightscout.androidaps.interfaces.ProfileInterface;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions;
import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventNewHistoryData;
import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload;
import info.nightscout.androidaps.plugins.PumpDanaR.activities.DanaRNSHistorySync;
@ -421,24 +421,15 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
*/
@Nullable
public static BgReading lastBg() {
List<BgReading> bgList = null;
List<BgReading> bgList = IobCobCalculatorPlugin.getPlugin().getBgReadings();
try {
Dao<BgReading, Long> daoBgReadings = MainApp.getDbHelper().getDaoBgReadings();
QueryBuilder<BgReading, Long> queryBuilder = daoBgReadings.queryBuilder();
queryBuilder.orderBy("date", false);
queryBuilder.limit(1L);
queryBuilder.where().ge("value", 39).and().eq("isValid", true);
PreparedQuery<BgReading> preparedQuery = queryBuilder.prepare();
bgList = daoBgReadings.query(preparedQuery);
} catch (SQLException e) {
log.error("Unhandled exception", e);
}
if (bgList != null && bgList.size() > 0)
return bgList.get(0);
else
if (bgList == null)
return null;
for (int i = 0; i < bgList.size(); i++)
if (bgList.get(i).value > 39)
return bgList.get(i);
return null;
}
/*