-
Notifications
You must be signed in to change notification settings - Fork 44
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/discovery load time spike #1579
Draft
jarvisraymond-uchicago
wants to merge
18
commits into
master
Choose a base branch
from
feat/discoveryLoadTimeSpike
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 17 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
55f62d2
feat(discoveryLoadTimeSpike): began creating prototype
jarvisraymond-uchicago 1fd18a4
feat(discoveryLoadTimeSpike): added progress bar
jarvisraymond-uchicago 5332d9a
feat(discoveryLoadTimeSpike): Added progress bars that can be toggle …
jarvisraymond-uchicago 8d70ce9
feat(discoveryLoadTimeSpike): Added logic to only batch load if condi…
jarvisraymond-uchicago f51fc1c
feat(discoveryLoadTimeSpike): Removed autoformatting from DiscoverySu…
jarvisraymond-uchicago a64f848
feat(discoveryLoadTimeSpike): Removed autoformatting from index.tsx
jarvisraymond-uchicago 5be3df0
feat(discoveryLoadTimeSpike): Removed autoformatting from Discovery.tsx
jarvisraymond-uchicago ca1f953
feat(discoveryLoadTimeSpike): Added injected CSS to make it look nice…
jarvisraymond-uchicago 187d30f
feat(discoveryLoadTimeSpike): Updated progress bar colors and progres…
jarvisraymond-uchicago 8684e1a
feat(discoveryLoadTimeSpike): Adjusted processingTimeDelay
jarvisraymond-uchicago 0629ce3
feat(discoveryLoadTimeSpike): updated logic to hide progress bar to u…
jarvisraymond-uchicago 25734db
feat(discoveryLoadTimeSpike): updated variables to try to make progre…
jarvisraymond-uchicago fa90e3e
feat(discoveryLoadTimeSpike): Moved comment to relevant code
jarvisraymond-uchicago 799e9c2
feat(discoveryLoadTimeSpike): Removed DiscoveryLoadingProgress, only …
jarvisraymond-uchicago 905b7e1
feat(discoveryLoadTimeSpike): added explanatory comments, cleaned up …
jarvisraymond-uchicago 0b7a4d7
feat(discoveryLoadTimeSpike): Reverted footer file
jarvisraymond-uchicago 06d7acc
feat(discoveryLoadTimeSpike): updated so the change is globally enabl…
jarvisraymond-uchicago fd8a086
feat(discoveryLoadTimeSpike): Updated name of studiesBatchCount to nu…
jarvisraymond-uchicago File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import { Progress } from 'antd'; | ||
|
||
interface DiscoveryLoadingProps { | ||
batchLoadingInfo: { allBatchesAreLoaded: boolean } | ||
} | ||
|
||
// this should probably be done in a CSS for production: | ||
const style = document.createElement('style'); | ||
style.type = 'text/css'; | ||
const css = '.discovery-header__dropdown-tags-container {margin-top: 15px;} .discovery-header{align-items:start;} '; | ||
style.innerHTML = css; | ||
document.head.appendChild(style); | ||
|
||
const DiscoveryLoadingProgressMini = ({ | ||
batchLoadingInfo, | ||
}: DiscoveryLoadingProps) => { | ||
const [percent, setPercent] = useState(0); | ||
const { allBatchesAreLoaded } = batchLoadingInfo; | ||
const [displayProgressBar, setDisplayProgressBar] = useState(true); | ||
|
||
// Fake loading UI | ||
const percentUpdateInterval = 500; | ||
const percentIncrementAmount = 5; | ||
useEffect(() => { | ||
const interval = setInterval(() => { | ||
setPercent((prevPercent) => prevPercent + percentIncrementAmount); | ||
}, percentUpdateInterval); | ||
return () => clearInterval(interval); | ||
}, [percent, allBatchesAreLoaded]); | ||
|
||
// hide the bar with a transition delay after the batches are loaded, | ||
// giving the browser some time to process the batch | ||
const delayTimeBeforeHidingProgressBar = 2000; | ||
useEffect(() => { | ||
if (allBatchesAreLoaded) { | ||
// Change displayProgressBar to false after delay | ||
setTimeout(() => { | ||
setDisplayProgressBar(false); | ||
}, delayTimeBeforeHidingProgressBar); | ||
} | ||
}, [allBatchesAreLoaded]); | ||
|
||
const progressContainerStyle = { | ||
textAlign: 'center', | ||
marginBottom: '5px', | ||
display: displayProgressBar ? 'block' : 'none', | ||
}; | ||
|
||
return ( | ||
<div style={progressContainerStyle}> | ||
<Progress | ||
width={80} | ||
showInfo={false} | ||
percent={allBatchesAreLoaded ? 100 : percent} | ||
status='success' | ||
strokeColor='#99286B' | ||
/> | ||
<p | ||
style={{ lineHeight: 'normal', textTransform: 'inherit' }} | ||
className='discovery-header__stat-label' | ||
> | ||
Loading studies... | ||
</p> | ||
</div> | ||
); | ||
}; | ||
|
||
export default DiscoveryLoadingProgressMini; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import { connect } from 'react-redux'; | ||
import _ from 'lodash'; | ||
|
||
import Discovery, { AccessLevel, AccessSortDirection, DiscoveryResource } from './Discovery'; | ||
import { DiscoveryConfig } from './DiscoveryConfig'; | ||
import { userHasMethodForServiceOnResource } from '../authMappingUtils'; | ||
|
@@ -10,7 +9,7 @@ import { | |
} from '../localconf'; | ||
import isEnabled from '../helpers/featureFlags'; | ||
import loadStudiesFromAggMDS from './aggMDSUtils'; | ||
import loadStudiesFromMDS from './MDSUtils'; | ||
import { loadStudiesFromMDS, getSomeStudiesFromMDS } from './MDSUtils'; | ||
|
||
const populateStudiesWithConfigInfo = (studies, config) => { | ||
if (!config.studies) { | ||
|
@@ -73,22 +72,58 @@ const DiscoveryWithMDSBackend: React.FC<{ | |
throw new Error('Could not find configuration for Discovery page. Check the portal config.'); | ||
} | ||
|
||
// Downloads and processes studies in two seperate batches | ||
// to improve load time & usability | ||
// Initially uses a smaller batch to load interface quickly | ||
// Then a batch with all the studies | ||
const [studiesBatchCount, setStudiesBatchCount] = useState(0); | ||
const expectedNumberOfTotalBatches = 2; | ||
const numberOfStudiesForSmallerBatch = 5; | ||
const numberOfStudiesForAllStudiesBatch = 2000; | ||
|
||
useEffect(() => { | ||
// If batch loading is Enabled, update the studiesBatchCount to enable calling of different batch sizes | ||
// with different parameters | ||
if (studiesBatchCount < expectedNumberOfTotalBatches) setStudiesBatchCount(studiesBatchCount + 1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: Update the variable name to "numberOfBatchesLoaded" |
||
|
||
const studyRegistrationValidationField = studyRegistrationConfig?.studyRegistrationValidationField; | ||
async function fetchRawStudies() { | ||
let loadStudiesFunction; | ||
const startTime = performance.now(); | ||
let loadStudiesFunction: Function; | ||
let loadStudiesParameters: any; | ||
if (isEnabled('discoveryUseAggMDS')) { | ||
loadStudiesFunction = loadStudiesFromAggMDS; | ||
loadStudiesParameters = studiesBatchCount === 1 | ||
? numberOfStudiesForSmallerBatch | ||
: numberOfStudiesForAllStudiesBatch; | ||
} else { | ||
loadStudiesFunction = loadStudiesFromMDS; | ||
loadStudiesFunction = getSomeStudiesFromMDS; | ||
loadStudiesParameters = props.config?.features?.guidType; | ||
} | ||
const rawStudiesRegistered = await loadStudiesFunction(props.config?.features?.guidType); | ||
let rawStudiesUnregistered = []; | ||
const rawStudiesRegistered = await loadStudiesFunction( | ||
loadStudiesParameters, | ||
); | ||
let rawStudiesUnregistered: any[] = []; | ||
if (isEnabled('studyRegistration')) { | ||
rawStudiesUnregistered = await loadStudiesFromMDS('unregistered_discovery_metadata'); | ||
rawStudiesUnregistered = rawStudiesUnregistered | ||
.map((unregisteredStudy) => ({ ...unregisteredStudy, [studyRegistrationValidationField]: false })); | ||
// Load fewer raw studies if on the first studies batch | ||
// Otherwise load them all | ||
rawStudiesUnregistered = studiesBatchCount === 1 | ||
? (rawStudiesUnregistered = await getSomeStudiesFromMDS( | ||
'unregistered_discovery_metadata', | ||
numberOfStudiesForSmallerBatch, | ||
)) | ||
: await loadStudiesFromMDS('unregistered_discovery_metadata'); | ||
rawStudiesUnregistered = rawStudiesUnregistered.map( | ||
(unregisteredStudy) => ({ | ||
...unregisteredStudy, | ||
[studyRegistrationValidationField]: false, | ||
}), | ||
); | ||
} | ||
const endTime = performance.now(); | ||
console.log( | ||
`Call to fetchRawStudies took ${endTime - startTime} milliseconds`, | ||
); | ||
return _.union(rawStudiesRegistered, rawStudiesUnregistered); | ||
} | ||
fetchRawStudies().then((rawStudies) => { | ||
|
@@ -167,16 +202,27 @@ const DiscoveryWithMDSBackend: React.FC<{ | |
|
||
// indicate discovery tag is active even if we didn't click a button to get here | ||
props.onDiscoveryPageActive(); | ||
}, []); | ||
}, [props, studiesBatchCount]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: Update the variable name to "numberOfBatchesLoaded" |
||
|
||
let studyRegistrationValidationField = studyRegistrationConfig?.studyRegistrationValidationField; | ||
if (!isEnabled('studyRegistration')) { | ||
studyRegistrationValidationField = undefined; | ||
} | ||
|
||
const batchLoadingInfo = { | ||
// All batches all loaded if the studies are not null and | ||
// their length is great than the studies for the smaller batches | ||
// from loadStudiesFromAggMDS and getSomeStudiesFromMDS | ||
allBatchesAreLoaded: studies === null | ||
? false | ||
: studies?.length > numberOfStudiesForSmallerBatch * 2, | ||
}; | ||
|
||
return ( | ||
<Discovery | ||
studies={studies === null ? [] : studies} | ||
studyRegistrationValidationField={studyRegistrationValidationField} | ||
batchLoadingInfo={batchLoadingInfo} | ||
{...props} | ||
/> | ||
); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: Update the variable name to "numberOfBatchesLoaded"