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

feat: improve review page loading times #3189

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion backend/docs/plantuml/statusChange.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,15 @@ data class SequenceEntryStatus(
val isRevocation: Boolean = false,
val submissionId: String,
val dataUseTerms: DataUseTerms,
val processedData: ProcessedData<GeneticSequence>?,
val originalData: OriginalData<GeneticSequence>?,
@Schema(description = "The preprocessing will be considered failed if this is not empty")
val errors: List<PreprocessingAnnotation>? = null,
@Schema(
description =
"Issues where data is not necessarily wrong, but the user might want to look into those warnings.",
fhennig marked this conversation as resolved.
Show resolved Hide resolved
)
val warnings: List<PreprocessingAnnotation>? = null,
) : AccessionVersionInterface

data class EditedSequenceEntryData(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ class CompressionService(private val backendConfig: BackendConfig) {
getDictionaryForAminoAcidSequence(gene, organism),
)

fun maybeDecompressSequencesInOriginalData(originalData: OriginalData<CompressedSequence>?, organism: Organism) =
if (originalData != null) decompressSequencesInOriginalData(originalData, organism) else null

fun decompressSequencesInOriginalData(originalData: OriginalData<CompressedSequence>, organism: Organism) =
OriginalData(
originalData.metadata,
Expand All @@ -84,6 +87,9 @@ class CompressionService(private val backendConfig: BackendConfig) {
},
)

fun maybeDecompressSequencesInProcessedData(processedData: ProcessedData<CompressedSequence>?, organism: Organism) =
if (processedData != null) decompressSequencesInProcessedData(processedData, organism) else null

fun decompressSequencesInProcessedData(processedData: ProcessedData<CompressedSequence>, organism: Organism) =
ProcessedData(
processedData.metadata,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -655,14 +655,16 @@ class SubmissionDatabaseService(
SequenceEntriesView.versionColumn,
SequenceEntriesView.submissionIdColumn,
SequenceEntriesView.statusColumn,
SequenceEntriesView.processingResultColumn,
SequenceEntriesView.isRevocationColumn,
SequenceEntriesView.groupIdColumn,
SequenceEntriesView.submitterColumn,
SequenceEntriesView.organismColumn,
SequenceEntriesView.submittedAtTimestampColumn,
SequenceEntriesView.errorsColumn,
SequenceEntriesView.warningsColumn,
SequenceEntriesView.processingResultColumn,
SequenceEntriesView.processedDataColumn,
SequenceEntriesView.originalDataColumn,
DataUseTermsTable.dataUseTermsTypeColumn,
DataUseTermsTable.restrictedUntilColumn,
)
Expand Down Expand Up @@ -710,6 +712,16 @@ class SubmissionDatabaseService(
DataUseTermsType.fromString(row[DataUseTermsTable.dataUseTermsTypeColumn]),
row[DataUseTermsTable.restrictedUntilColumn],
),
processedData = compressionService.maybeDecompressSequencesInProcessedData(
row[SequenceEntriesView.processedDataColumn],
organism,
),
originalData = compressionService.maybeDecompressSequencesInOriginalData(
row[SequenceEntriesView.originalDataColumn],
organism,
),
errors = row[SequenceEntriesView.errorsColumn],
warnings = row[SequenceEntriesView.warningsColumn],
)
}

Expand Down
44 changes: 8 additions & 36 deletions website/src/components/ReviewPage/ReviewCard.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { type FC } from 'react';
import { Tooltip } from 'react-tooltip';

import { backendClientHooks } from '../../services/serviceHooks.ts';
import {
type DataUseTerms,
processedStatus,
Expand All @@ -11,12 +10,9 @@ import {
restrictedDataUseTermsType,
type SequenceEntryStatus,
type SequenceEntryStatusNames,
type SequenceEntryToEdit,
errorsProcessingResult,
warningsProcessingResult,
} from '../../types/backend.ts';
import type { ClientConfig } from '../../types/runtimeConfig.ts';
import { createAuthorizationHeader } from '../../utils/createAuthorizationHeader.ts';
import { displayMetadataField } from '../../utils/displayMetadataField.ts';
import { getAccessionVersionString } from '../../utils/extractAccessionVersion.ts';
import BiTrash from '~icons/bi/trash';
Expand All @@ -34,21 +30,14 @@ type ReviewCardProps = {
deleteAccessionVersion: () => void;
approveAccessionVersion: () => void;
editAccessionVersion: () => void;
clientConfig: ClientConfig;
organism: string;
accessToken: string;
};

export const ReviewCard: FC<ReviewCardProps> = ({
sequenceEntryStatus,
approveAccessionVersion,
deleteAccessionVersion,
editAccessionVersion,
clientConfig,
organism,
accessToken,
}) => {
const { isLoading, data } = useGetMetadataAndAnnotations(organism, clientConfig, accessToken, sequenceEntryStatus);
return (
<div className='px-3 py-2 relative transition-all duration-500'>
<div className='flex'>
Expand All @@ -65,7 +54,7 @@ export const ReviewCard: FC<ReviewCardProps> = ({
keyName={getAccessionVersionString(sequenceEntryStatus)}
value={sequenceEntryStatus.submissionId}
/>
{data !== undefined && <MetadataList data={data} isLoading={isLoading} />}
<MetadataList data={sequenceEntryStatus} />
{sequenceEntryStatus.isRevocation && (
<KeyValueComponent
accessionVersion={getAccessionVersionString(sequenceEntryStatus)}
Expand All @@ -83,11 +72,11 @@ export const ReviewCard: FC<ReviewCardProps> = ({
/>
</div>

{data?.errors?.length !== undefined && data.errors.length > 0 && (
<Errors errors={data.errors} accession={sequenceEntryStatus.accession} />
{sequenceEntryStatus.errors?.length !== undefined && sequenceEntryStatus.errors.length > 0 && (
<Errors errors={sequenceEntryStatus.errors} accession={sequenceEntryStatus.accession} />
)}
{data?.warnings?.length !== undefined && data.warnings.length > 0 && (
<Warnings warnings={data.warnings} accession={sequenceEntryStatus.accession} />
{sequenceEntryStatus.warnings?.length !== undefined && sequenceEntryStatus.warnings.length > 0 && (
<Warnings warnings={sequenceEntryStatus.warnings} accession={sequenceEntryStatus.accession} />
)}
</div>
);
Expand Down Expand Up @@ -171,15 +160,14 @@ const ButtonBar: FC<ButtonBarProps> = ({
};

type MetadataListProps = {
data: SequenceEntryToEdit;
isLoading: boolean;
data: SequenceEntryStatus;
};

const isAnnotationPresent = (metadataField: string) => (item: ProcessingAnnotation) =>
item.source[0].name === metadataField;

const MetadataList: FC<MetadataListProps> = ({ data, isLoading }) =>
!isLoading &&
const MetadataList: FC<MetadataListProps> = ({ data }) =>
data.processedData !== null &&
Object.entries(data.processedData.metadata).map(([metadataName, value], index) =>
value === null ? null : (
<KeyValueComponent
Expand Down Expand Up @@ -412,19 +400,3 @@ function getTextColorAndMessages(
secondaryMessages: undefined,
};
}

function useGetMetadataAndAnnotations(
organism: string,
clientConfig: ClientConfig,
accessToken: string,
sequenceEntryStatus: SequenceEntryStatus,
) {
const { status, accession, version } = sequenceEntryStatus;
return backendClientHooks(clientConfig).useGetDataToEdit(
{
headers: createAuthorizationHeader(accessToken),
params: { organism, accession, version },
},
{ enabled: status !== receivedStatus && status !== inProcessingStatus },
);
}
74 changes: 74 additions & 0 deletions website/src/components/ReviewPage/ReviewPage.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
noIssuesProcessingResult,
warningsProcessingResult,
errorsProcessingResult,
type ProcessingAnnotation,
} from '../../types/backend.ts';

const unreleasedSequencesRegex = /You do not currently have any unreleased sequences awaiting review.*/;
Expand All @@ -31,6 +32,63 @@ function renderReviewPage() {
);
}

export const metadataKey = 'originalMetaDataField';
export const editableEntry = 'originalMetaDataValue';
const testErrors: ProcessingAnnotation[] = [
{
source: [
{
name: metadataKey,
type: 'Metadata',
},
],
message: 'errorMessage',
},
];

const testWarnings: ProcessingAnnotation[] = [
{
source: [
{
name: metadataKey,
type: 'Metadata',
},
],
message: 'warningMessage',
},
];

const testOriginalData = {
metadata: {
[metadataKey]: editableEntry,
},
unalignedNucleotideSequences: {
originalSequenceName: 'originalUnalignedNucleotideSequencesValue',
},
};

const testProcessedData = {
metadata: {
processedMetaDataField: 'processedMetaDataValue',
nullField: null,
},
unalignedNucleotideSequences: {
unalignedProcessedSequenceName: 'processedUnalignedNucleotideSequencesValue',
},
alignedNucleotideSequences: {
alignedProcessedSequenceName: 'processedAlignedNucleotideSequencesValue',
},
nucleotideInsertions: {
processedInsertionSequenceName: ['nucleotideInsertion1', 'nucleotideInsertion2'],
},
alignedAminoAcidSequences: {
alignedProcessedGeneName: 'processedAminoAcidSequencesValue',
},
aminoAcidInsertions: {
processedInsertionGeneName: ['aminoAcidInsertion1', 'aminoAcidInsertion2'],
},
};

const receivedTestData: SequenceEntryStatus = {
submissionId: 'custom1',
status: receivedStatus,
Expand All @@ -41,6 +99,10 @@ const receivedTestData: SequenceEntryStatus = {
dataUseTerms: openDataUseTerms,
groupId: 42,
submitter: 'submitter',
originalData: testOriginalData,
processedData: testProcessedData,
errors: testErrors,
warnings: testWarnings,
};

const processingTestData: SequenceEntryStatus = {
Expand All @@ -53,6 +115,10 @@ const processingTestData: SequenceEntryStatus = {
dataUseTerms: openDataUseTerms,
groupId: 42,
submitter: 'submitter',
originalData: testOriginalData,
processedData: testProcessedData,
errors: testErrors,
warnings: testWarnings,
};

const erroneousTestData: SequenceEntryStatus = {
Expand All @@ -65,6 +131,10 @@ const erroneousTestData: SequenceEntryStatus = {
dataUseTerms: openDataUseTerms,
groupId: 42,
submitter: 'submitter',
originalData: testOriginalData,
processedData: testProcessedData,
errors: testErrors,
warnings: testWarnings,
};

const awaitingApprovalTestData: SequenceEntryStatus = {
Expand All @@ -77,6 +147,10 @@ const awaitingApprovalTestData: SequenceEntryStatus = {
dataUseTerms: openDataUseTerms,
groupId: 42,
submitter: 'submitter',
originalData: testOriginalData,
processedData: testProcessedData,
errors: testErrors,
warnings: testWarnings,
};

const emptyStatusCounts = {
Expand Down
3 changes: 0 additions & 3 deletions website/src/components/ReviewPage/ReviewPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,6 @@ const InnerReviewPage: FC<ReviewPageProps> = ({ clientConfig, organism, group, a
editAccessionVersion={() => {
window.location.href = routes.editPage(organism, sequence);
}}
clientConfig={clientConfig}
organism={organism}
accessToken={accessToken}
/>
</div>
);
Expand Down
18 changes: 18 additions & 0 deletions website/src/types/backend.ts
Copy link
Member

Choose a reason for hiding this comment

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

I think that if we were to make the changes in this PR we need to not send sequences in the endpoint used on the review page. This is is because:

  • sequences for some viruses are 200 kb, 100 per page = 20 MB, polling constantly = a lot of bandwidth

We may want to delay making any change here for now for simplicity to avoid having to add extra types etc.

Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,24 @@ export const sequenceEntryStatus = accessionVersion.merge(
dataUseTerms,
groupId: z.number(),
submitter: z.string(),
errors: z.array(processingAnnotation).nullable(),
warnings: z.array(processingAnnotation).nullable(),
originalData: z
.object({
metadata: unprocessedMetadataRecord,
unalignedNucleotideSequences: z.record(z.string()),
})
.nullable(),
processedData: z
.object({
metadata: metadataRecord,
unalignedNucleotideSequences: z.record(z.string().nullable()),
alignedNucleotideSequences: z.record(z.string().nullable()),
nucleotideInsertions: z.record(z.array(z.string())),
alignedAminoAcidSequences: z.record(z.string().nullable()),
aminoAcidInsertions: z.record(z.array(z.string())),
})
.nullable(),
}),
);

Expand Down
Loading