From 541a1fed6edd90c32a7938369722f940e7ed2029 Mon Sep 17 00:00:00 2001 From: Cornelius Roemer Date: Sat, 23 Nov 2024 09:38:03 +0100 Subject: [PATCH] Simplify get sequences a bitm ore --- .../controller/SubmissionController.kt | 2 +- .../submission/SubmissionDatabaseService.kt | 45 +++++++------------ 2 files changed, 18 insertions(+), 29 deletions(-) diff --git a/backend/src/main/kotlin/org/loculus/backend/controller/SubmissionController.kt b/backend/src/main/kotlin/org/loculus/backend/controller/SubmissionController.kt index 29eb1a496..742081550 100644 --- a/backend/src/main/kotlin/org/loculus/backend/controller/SubmissionController.kt +++ b/backend/src/main/kotlin/org/loculus/backend/controller/SubmissionController.kt @@ -346,7 +346,7 @@ open class SubmissionController( description = "Filter by status. If not provided, all statuses are considered.", ) @RequestParam(required = false) statusesFilter: List?, @Parameter( - description = "Filter by processing result. If not provided, all results are considered. " + + description = "Filter by processing result. If not provided, no filtering on processing result is done. " + "This only filters sequences that are actually in the PROCESSED status, and does not affect " + "sequences in any other status.", ) @RequestParam(required = false) processingResultFilter: List?, diff --git a/backend/src/main/kotlin/org/loculus/backend/service/submission/SubmissionDatabaseService.kt b/backend/src/main/kotlin/org/loculus/backend/service/submission/SubmissionDatabaseService.kt index 6ff0d12c7..d77315bd0 100644 --- a/backend/src/main/kotlin/org/loculus/backend/service/submission/SubmissionDatabaseService.kt +++ b/backend/src/main/kotlin/org/loculus/backend/service/submission/SubmissionDatabaseService.kt @@ -18,7 +18,6 @@ import org.jetbrains.exposed.sql.SqlExpressionBuilder.plus import org.jetbrains.exposed.sql.Transaction import org.jetbrains.exposed.sql.alias import org.jetbrains.exposed.sql.and -import org.jetbrains.exposed.sql.andWhere import org.jetbrains.exposed.sql.batchInsert import org.jetbrains.exposed.sql.booleanParam import org.jetbrains.exposed.sql.deleteWhere @@ -640,11 +639,20 @@ class SubmissionDatabaseService( "processingResultFilter: $processingResultFilter, page: $page, pageSize: $size)" } - val listOfStatuses = statusesFilter ?: Status.entries - + val statusCondition = when (statusesFilter) { + null -> Op.TRUE + else -> SequenceEntriesView.statusIsOneOf(statusesFilter) + } val groupCondition = getGroupCondition(groupIdsFilter, authenticatedUser) + val organismCondition = SequenceEntriesView.organismIs(organism) + val processingResultCondition = when (processingResultFilter) { + null -> Op.TRUE + else -> SequenceEntriesView.processingResultIsOneOf(processingResultFilter) or + // processingResultFilter has no effect on sequences in states other than PROCESSED + not(SequenceEntriesView.statusIs(Status.PROCESSED)) + } - val baseQuery = SequenceEntriesView + val entries = SequenceEntriesView .join( DataUseTermsTable, JoinType.LEFT, @@ -661,36 +669,17 @@ class SubmissionDatabaseService( SequenceEntriesView.isRevocationColumn, SequenceEntriesView.groupIdColumn, SequenceEntriesView.submitterColumn, - SequenceEntriesView.organismColumn, - SequenceEntriesView.submittedAtTimestampColumn, - SequenceEntriesView.errorsColumn, - SequenceEntriesView.warningsColumn, SequenceEntriesView.processingResultColumn, DataUseTermsTable.dataUseTermsTypeColumn, DataUseTermsTable.restrictedUntilColumn, ) - .where { groupCondition } - .andWhere { SequenceEntriesView.organismIs(organism) } + .where { groupCondition and organismCondition and statusCondition and processingResultCondition } .orderBy(SequenceEntriesView.accessionColumn) - - val filteredQuery = baseQuery.andWhere { - SequenceEntriesView.statusIsOneOf(listOfStatuses) - } - - processingResultFilter?.let { processingResultsToInclude -> - filteredQuery.andWhere { - SequenceEntriesView.processingResultIsOneOf(processingResultsToInclude) or - not(SequenceEntriesView.statusIs(Status.PROCESSED)) + .apply { + if (page != null && size != null) { + limit(size).offset((page * size).toLong()) + } } - } - - val pagedQuery = if (page != null && size != null) { - filteredQuery.limit(size).offset((page * size).toLong()) - } else { - filteredQuery - } - - val entries = pagedQuery .map { row -> SequenceEntryStatus( accession = row[SequenceEntriesView.accessionColumn],