Comments (6)
Could it be because you are calling FhirEngine.get
on UI thread ?
May be try wrapping your call with withContext(Dispatchers.IO) { }
from android-fhir.
From discussion with @yigit, this particular read api should be executed independently of any transaction.
Reason (in Yigt's words): The transaction you add there doesn't really help with anything because you are only doing a read inside that transaction and it is a single read. SQLite will already do a "read transaction" for it implicitly, which will make that consistent.
Would you like to work on this @LZRS ?
from android-fhir.
Could it be because you are calling
FhirEngine.get
on UI thread ? May be try wrapping your call withwithContext(Dispatchers.IO) { }
Using thewithContext(Dispatchers.IO) { }
, the delay still seems to happen
Also added a test with this branch
diff --git a/engine/src/androidTest/java/com/google/android/fhir/db/impl/DatabaseImplTest.kt b/engine/src/androidTest/java/com/google/android/fhir/db/impl/DatabaseImplTest.kt
index 16446abf..31a1e35f 100644
--- a/engine/src/androidTest/java/com/google/android/fhir/db/impl/DatabaseImplTest.kt
+++ b/engine/src/androidTest/java/com/google/android/fhir/db/impl/DatabaseImplTest.kt
@@ -50,12 +50,16 @@ import com.google.android.fhir.testing.readJsonArrayFromFile
import com.google.android.fhir.versionId
import com.google.common.truth.Correspondence
import com.google.common.truth.Truth.assertThat
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.delay
import java.math.BigDecimal
import java.time.Instant
import java.util.Date
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.flowOf
+import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
+import kotlinx.coroutines.withContext
import org.hl7.fhir.r4.model.Address
import org.hl7.fhir.r4.model.CarePlan
import org.hl7.fhir.r4.model.CodeableConcept
@@ -120,7 +124,7 @@ class DatabaseImplTest {
private fun buildFhirService(customSearchParameter: List<SearchParameter>? = null) {
services =
FhirServices.builder(context)
- .inMemory()
+// .inMemory()
.apply {
if (encrypted) enableEncryptionIfSupported()
setSearchParameters(customSearchParameter)
@@ -150,6 +154,27 @@ class DatabaseImplTest {
assertResourceEquals(TEST_PATIENT_2, database.select(ResourceType.Patient, TEST_PATIENT_2_ID))
}
+ @Test
+ fun select_transactionDelay() {
+ runBlocking {
+ database.insert(TEST_PATIENT_1)
+
+ launch {
+ println("Transaction started")
+ database.withTransaction {
+ delay(3000)
+ }
+ println("Transaction completed")
+ }
+
+ launch {
+ println("Patient Loading")
+ database.select(ResourceType.Patient, TEST_PATIENT_1_ID)
+ println("Patient Loaded")
+ }
+ }
+ }
+
@Test
fun update_existentResource_shouldUpdateResource() = runBlocking {
val patient = Patient()
It printed out
05-25 01:50:02.327 12533 12556 I TestRunner: started: select_transactionDelay[encrypted=false](com.google.android.fhir.db.impl.DatabaseImplTest)
05-25 01:50:03.777 12533 12556 I System.out: Transaction started
05-25 01:50:03.777 12533 12556 I System.out: Patient Loading
05-25 01:50:06.782 12533 12556 I System.out: Transaction completed
05-25 01:50:06.791 12533 12556 I System.out: Patient Loaded
05-25 01:50:06.796 12533 12556 I TestRunner: finished: select_transactionDelay[encrypted=false](com.google.android.fhir.db.impl.DatabaseImplTest)
from android-fhir.
Removing the db.withTransaction
from the select method
diff --git a/engine/src/main/java/com/google/android/fhir/db/impl/DatabaseImpl.kt b/engine/src/main/java/com/google/android/fhir/db/impl/DatabaseImpl.kt
index b156b467..4fab6b5a 100644
--- a/engine/src/main/java/com/google/android/fhir/db/impl/DatabaseImpl.kt
+++ b/engine/src/main/java/com/google/android/fhir/db/impl/DatabaseImpl.kt
@@ -174,12 +174,17 @@ internal class DatabaseImpl(
}
override suspend fun select(type: ResourceType, id: String): Resource {
- return db.withTransaction {
- resourceDao.getResource(resourceId = id, resourceType = type)?.let {
+// return db.withTransaction {
+// resourceDao.getResource(resourceId = id, resourceType = type)?.let {
+// iParser.parseResource(it)
+// }
+// ?: throw ResourceNotFoundException(type.name, id)
+// } as Resource
+
+ return resourceDao.getResource(resourceId = id, resourceType = type)?.let {
iParser.parseResource(it)
- }
+ } as? Resource
?: throw ResourceNotFoundException(type.name, id)
- } as Resource
}
override suspend fun insertSyncedResources(resources: List<Resource>) {
It prints
05-25 02:05:02.355 12752 12775 I TestRunner: started: select_transactionDelay[encrypted=false](com.google.android.fhir.db.impl.DatabaseImplTest)
05-25 02:05:03.771 12752 12775 I System.out: Transaction started
05-25 02:05:03.771 12752 12775 I System.out: Patient Loading
05-25 02:05:03.776 12752 12775 I System.out: Patient Loaded
05-25 02:05:06.773 12752 12775 I System.out: Transaction completed
05-25 02:05:06.779 12752 12775 I TestRunner: finished: select_transactionDelay[encrypted=false](com.google.android.fhir.db.impl.DatabaseImplTest)
from android-fhir.
@yigit Need your help here.
I did some research but couldn't find anything on google. Only found one suggestion to make DAO layer asynchronous by providing a flow (or LiveData) of values. But I don't think this will help the above issue.
from android-fhir.
From discussion with @yigit, this particular read api should be executed independently of any transaction.
Reason (in Yigt's words): The transaction you add there doesn't really help with anything because you are only doing a read inside that transaction and it is a single read. SQLite will already do a "read transaction" for it implicitly, which will make that consistent.
Would you like to work on this @LZRS ?
Yeah, I would like to work on the issue.
Also on the same, would it also affect reads using FhirEngine#search , that joins to other tables?
from android-fhir.
Related Issues (20)
- Repeated Group: Anomalous behaviour of enableWhen expressions in a repeated group HOT 7
- Upon deleting a repeatedGroup answer, the other repeatedGroup answers are also reset. HOT 1
- UI/UX Design: The name for a specific field be equidistant from its intended field and another field HOT 2
- UI/UX Design: Warning text (i.e. text that are nudging clinical decision guideline to users) looks visually similar with other fields HOT 1
- Isolating Room Components with hapi dependencies HOT 1
- Incorporate `%context` into variable expression evaluation
- > Could not PUT 'https://maven.pkg.github.com/google/android-fhir/com/google/android/fhir/common/0.1.0-alpha05-SNAPSHOT/common-0.1.0-alpha05-20240710.120641-20.module'. Received status code 409 from server: Conflict HOT 1
- https://google.github.io/android-fhir/ documentation website is broken HOT 4
- Using GitHub Codespaces for documentation writing does not work due to: "The SDK directory is not writable (/opt/android)" error HOT 7
- Dependabot not creating updates? (Which?) HOT 9
- Helper function to match the correct pair of qItem and qrItem HOT 4
- Extending the db.transaction removal fix to the FhirEngine.search HOT 1
- Allow to keep using checkbox group when there the items are at least 10 HOT 2
- Reenable workflow test HOT 1
- Async process for getQuestionnairePages HOT 7
- Paginated Questionnaires: Validate before going to the next page HOT 3
- Flyover text as secondary dialog title HOT 22
- itemMediaView image flicker when loading image HOT 3
- Keyboard hides itself when focusing to open-choice text box HOT 2
- Matching of the correct pair of qItem and qrItem fails for repeated groups HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from android-fhir.