-
Notifications
You must be signed in to change notification settings - Fork 60
Speedup pubilc courses rpc #1929
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
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,6 +50,17 @@ type CoursesDaoImpl struct { | |
| usersDao UsersDao | ||
| } | ||
|
|
||
| func publicCourseStreamFilter() func(*gorm.DB) *gorm.DB { | ||
| latestRecording := DB.Model(&model.Stream{}). | ||
| Select("MAX(start)"). | ||
| Where("course_id = streams.course_id AND recording = ?", true) | ||
|
|
||
| return func(db *gorm.DB) *gorm.DB { | ||
| return db.Where("(recording = ? AND start = (?)) OR start > NOW()", true, latestRecording). | ||
|
Member
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. This will yield all upcoming streams, no?
Member
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. Maybe something like this works? |
||
| Order("start asc") | ||
| } | ||
| } | ||
|
|
||
| func NewCoursesDao() CoursesDaoImpl { | ||
| return CoursesDaoImpl{db: DB, usersDao: NewUsersDao()} | ||
| } | ||
|
|
@@ -161,9 +172,8 @@ func (d CoursesDaoImpl) GetPublicCourses(year int, term string) (courses []model | |
| } | ||
| var publicCourses []model.Course | ||
|
|
||
| err = DB.Preload("Streams", func(db *gorm.DB) *gorm.DB { | ||
| return db.Order("start asc") | ||
| }).Find(&publicCourses, "visibility = 'public' AND teaching_term = ? AND year = ?", | ||
| err = DB.Preload("Streams", publicCourseStreamFilter()).Find(&publicCourses, | ||
| "visibility = 'public' AND teaching_term = ? AND year = ?", | ||
| term, year).Error | ||
|
|
||
| if err == nil { | ||
|
|
@@ -179,9 +189,7 @@ func (d CoursesDaoImpl) GetPublicAndLoggedInCourses(year int, term string) (cour | |
| } | ||
| var publicCourses []model.Course | ||
|
|
||
| err = DB.Preload("Streams", func(db *gorm.DB) *gorm.DB { | ||
| return db.Order("start asc") | ||
| }).Find(&publicCourses, | ||
| err = DB.Preload("Streams", publicCourseStreamFilter()).Find(&publicCourses, | ||
| "(visibility = 'public' OR visibility = 'loggedin') AND teaching_term = ? AND year = ?", term, year).Error | ||
| if err == nil { | ||
| Cache.SetWithTTL(fmt.Sprintf("publicAndLoggedInCourses%d%v", year, term), publicCourses, 1, time.Minute) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| package dao | ||
|
Member
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. What's that file? Either add tests or delete |
||
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.
here I'd prefer a minute just to shield us from spikes during hot hours when large streams start.