Skip to content

Commit

Permalink
Move the parallelized mapping outside db transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
LZRS committed Nov 8, 2024
1 parent 11ed6f0 commit ffed82a
Showing 1 changed file with 35 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -229,49 +229,54 @@ internal class DatabaseImpl(
override suspend fun <R : Resource> search(
query: SearchQuery,
): List<ResourceWithUUID<R>> {
return db.withTransaction {
resourceDao.getResources(SimpleSQLiteQuery(query.query, query.args.toTypedArray())).pmap(
Dispatchers.Default,
) {
ResourceWithUUID(
it.uuid,
FhirContext.forR4Cached().newJsonParser().parseResource(it.serializedResource) as R,
)
val dbResult =
db.withTransaction {
resourceDao.getResources(SimpleSQLiteQuery(query.query, query.args.toTypedArray()))
}

return dbResult.pmap(
Dispatchers.Default,
) {
ResourceWithUUID(
it.uuid,
FhirContext.forR4Cached().newJsonParser().parseResource(it.serializedResource) as R,
)
}
}

override suspend fun searchForwardReferencedResources(
query: SearchQuery,
): List<ForwardIncludeSearchResult> {
return db.withTransaction {
resourceDao
.getForwardReferencedResources(SimpleSQLiteQuery(query.query, query.args.toTypedArray()))
.pmap(Dispatchers.Default) {
ForwardIncludeSearchResult(
it.matchingIndex,
it.baseResourceUUID,
FhirContext.forR4Cached().newJsonParser().parseResource(it.serializedResource)
as Resource,
)
}
val dbResult =
db.withTransaction {
resourceDao.getForwardReferencedResources(
SimpleSQLiteQuery(query.query, query.args.toTypedArray()),
)
}
return dbResult.pmap(Dispatchers.Default) {
ForwardIncludeSearchResult(
it.matchingIndex,
it.baseResourceUUID,
FhirContext.forR4Cached().newJsonParser().parseResource(it.serializedResource) as Resource,
)
}
}

override suspend fun searchReverseReferencedResources(
query: SearchQuery,
): List<ReverseIncludeSearchResult> {
return db.withTransaction {
resourceDao
.getReverseReferencedResources(SimpleSQLiteQuery(query.query, query.args.toTypedArray()))
.pmap(Dispatchers.Default) {
ReverseIncludeSearchResult(
it.matchingIndex,
it.baseResourceTypeAndId,
FhirContext.forR4Cached().newJsonParser().parseResource(it.serializedResource)
as Resource,
)
}
val dbResult =
db.withTransaction {
resourceDao.getReverseReferencedResources(
SimpleSQLiteQuery(query.query, query.args.toTypedArray()),
)
}
return dbResult.pmap(Dispatchers.Default) {
ReverseIncludeSearchResult(
it.matchingIndex,
it.baseResourceTypeAndId,
FhirContext.forR4Cached().newJsonParser().parseResource(it.serializedResource) as Resource,
)
}
}

Expand Down

0 comments on commit ffed82a

Please sign in to comment.