Skip to content

Speedup pubilc courses rpc - #1929

Open
coolgirl19 wants to merge 2 commits into
devfrom
feat/speedup-pubic-courses-rpc
Open

Speedup pubilc courses rpc#1929
coolgirl19 wants to merge 2 commits into
devfrom
feat/speedup-pubic-courses-rpc

Conversation

@coolgirl19

Copy link
Copy Markdown
Contributor

No description provided.

Comment thread apiv2/server/course.go
}

if user == nil {
dao.Cache.SetWithTTL(fmt.Sprintf("publicCoursesSummary-%d-%s", year, term), resp, 1, 6*time.Hour)

Copy link
Copy Markdown
Member

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.

Comment thread dao/courses.go
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).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This will yield all upcoming streams, no?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe something like this works?

// Subquery 1: Latest past recording per course
latestRecording := DB.Model(&model.Stream{}).
    Select("MAX(start)").
    Where("course_id = streams.course_id AND recording = ? AND start <= NOW()", true)

// Subquery 2: Next upcoming stream per course
nextUpcoming := DB.Model(&model.Stream{}).
    Select("MIN(start)").
    Where("course_id = streams.course_id AND start > NOW()")

// Combined Filter
func publicCourseStreamFilter() func(*gorm.DB) *gorm.DB {
    return func(db *gorm.DB) *gorm.DB {
        return db.Where("start = (?) OR start = (?)", latestRecording, nextUpcoming).
            Order("start asc")
    }
}

Comment thread dao/courses_test.go
@@ -0,0 +1 @@
package dao

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What's that file? Either add tests or delete

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants