Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move the parallelized mapping outside db transaction #2715

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
)
}
Comment on lines +232 to 244
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The updated code adds more readability, which is nice. But I'm ok w the previous too.
I've no strong opinion about this

}

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
Loading