Skip to content

Commit 940c33f

Browse files
authored
Merge pull request #2340 from StoDevX/cs-speed-up-load
Only load course data if it hasn't been loaded or is out of date
2 parents c2da513 + 9ef7530 commit 940c33f

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

source/views/sis/course-search/search.js

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,21 +73,27 @@ class CourseSearchView extends React.PureComponent<Props, State> {
7373
}
7474

7575
loadData = () => {
76-
// 1. load the cached courses
77-
// 2. if any courses are cached, hide the spinner
78-
// 3. either way, start updating courses in the background
79-
// 4. when everything is done, make sure the spinner is hidden
8076
this.setState(() => ({dataLoading: true}))
81-
this.props
82-
.loadCourseDataIntoMemory()
83-
.then(() => areAnyTermsCached())
84-
.then(anyTermsCached => {
85-
if (anyTermsCached) {
86-
this.doneLoading()
87-
}
88-
return this.props.updateCourseData()
89-
})
90-
.finally(() => this.doneLoading())
77+
if (this.props.courseDataState !== 'ready') {
78+
// If the data has not been loaded into Redux State:
79+
// 1. load the cached courses
80+
// 2. if any courses are cached, hide the spinner
81+
// 3. either way, start updating courses in the background
82+
// 4. when everything is done, make sure the spinner is hidden
83+
this.props
84+
.loadCourseDataIntoMemory()
85+
.then(() => areAnyTermsCached())
86+
.then(anyTermsCached => {
87+
if (anyTermsCached) {
88+
this.doneLoading()
89+
}
90+
return this.props.updateCourseData()
91+
})
92+
.finally(() => this.doneLoading())
93+
} else {
94+
// If the course data is already in Redux State, check for update
95+
this.props.updateCourseData().then(() => this.doneLoading())
96+
}
9197
}
9298

9399
doneLoading = () => this.setState(() => ({dataLoading: false}))

0 commit comments

Comments
 (0)