mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2026-07-31 07:44:24 +02:00
Health Connect: Use database read lock
This commit is contained in:
+2
-2
@@ -369,7 +369,7 @@ class HealthConnectUtils {
|
||||
val activityBasedSamples: List<ActivitySample>? =
|
||||
if (dataType == HealthConnectPermissionManager.HealthConnectDataType.ACTIVITY ||
|
||||
dataType == HealthConnectPermissionManager.HealthConnectDataType.SLEEP) {
|
||||
GBApplication.acquireDB().use { db ->
|
||||
GBApplication.acquireDbReadOnly().use { db ->
|
||||
getActivitySamples(db, gbDevice, queryStartTs.epochSecond.toInt(), currentSliceEndTs.epochSecond.toInt())
|
||||
}
|
||||
} else {
|
||||
@@ -480,7 +480,7 @@ class HealthConnectUtils {
|
||||
deviceCoordinator: DeviceCoordinator,
|
||||
dataType: HealthConnectPermissionManager.HealthConnectDataType
|
||||
): Pair<Instant, Instant>? {
|
||||
return GBApplication.acquireDB().use { db ->
|
||||
return GBApplication.acquireDbReadOnly().use { db ->
|
||||
val deviceFromDb = DBHelper.getDevice(gbDevice, db.daoSession)
|
||||
if (deviceFromDb == null) {
|
||||
CompanionLogger.error("$HC_SYNC_TAG Device not found in database for address: {}", gbDevice.address)
|
||||
|
||||
+1
-1
@@ -75,7 +75,7 @@ internal abstract class AbstractTimeSampleSyncer<TSample : TimeSample, TRecord :
|
||||
|
||||
// Fetch samples
|
||||
val samples: List<TSample> = try {
|
||||
GBApplication.acquireDB().use { dbInstance ->
|
||||
GBApplication.acquireDbReadOnly().use { dbInstance ->
|
||||
val provider = getSampleProvider(gbDevice, dbInstance.daoSession)
|
||||
if (provider == null) {
|
||||
logger.info("$recordTypeName sample provider not available for device '$deviceName'.")
|
||||
|
||||
+1
-1
@@ -215,7 +215,7 @@ internal object RecordedWorkoutSyncer {
|
||||
sliceEndBoundary: Instant
|
||||
): List<BaseActivitySummary> {
|
||||
try {
|
||||
GBApplication.acquireDB().use { db ->
|
||||
GBApplication.acquireDbReadOnly().use { db ->
|
||||
val device = DBHelper.getDevice(gbDevice, db.daoSession)
|
||||
if (device == null) {
|
||||
LOG.warn("Device not found in database for '{}'", gbDevice.aliasOrName)
|
||||
|
||||
+2
-2
@@ -67,7 +67,7 @@ internal object TemperatureSyncer : HealthConnectSyncer {
|
||||
}
|
||||
|
||||
val samples: List<TemperatureSample> = try {
|
||||
GBApplication.acquireDB().use { db ->
|
||||
GBApplication.acquireDbReadOnly().use { db ->
|
||||
val provider = gbDevice.deviceCoordinator.getTemperatureSampleProvider(gbDevice, db.daoSession)
|
||||
if (provider == null) {
|
||||
LOG.warn("TemperatureSampleProvider not found for device '$deviceName'. Skipping Temperature sync for slice $sliceStartBoundary to $sliceEndBoundary.")
|
||||
@@ -230,7 +230,7 @@ internal object TemperatureSyncer : HealthConnectSyncer {
|
||||
dayEnd
|
||||
)
|
||||
|
||||
val samplesForDay: List<TemperatureSample> = GBApplication.acquireDB().use { db ->
|
||||
val samplesForDay: List<TemperatureSample> = GBApplication.acquireDbReadOnly().use { db ->
|
||||
val tempProvider = gbDevice.deviceCoordinator.getTemperatureSampleProvider(gbDevice, db.daoSession)
|
||||
if (tempProvider == null) {
|
||||
LOG.warn("SkinBaselineHelper for '$deviceAddress': TemperatureSampleProvider not found. Cannot calculate daily average for $targetDayStart.")
|
||||
|
||||
Reference in New Issue
Block a user