···76 return &livestream, nil
77}
7879-// type for livestream with seg start time
80-type LivestreamWithSegmentStartTime struct {
81- Livestream
82- // should be latest_segments.latest_segment_start_time in the query
83- LatestSegmentStartTime string
84-}
85-86// GetLatestLivestreams returns the most recent livestreams, given a limit and a cursor
87// Only gets livestreams with a valid segment no less than 30 seconds old
88func (m *DBModel) GetLatestLivestreams(limit int, before *time.Time) ([]Livestream, error) {
89- var recentLivestreams []LivestreamWithSegmentStartTime
90 thirtySecondsAgo := time.Now().Add(-30 * time.Second)
9192 // get latest segment for the repo DID
···96 m.DB.Table("segments").
97 Select("repo_did, MAX(start_time)").
98 Group("repo_did")).
99- Where("start_time > ?", thirtySecondsAgo).
100 Group("repo_did")
101102 rankedLivestreamsSubQuery := m.DB.Table("livestreams").
···130 return nil, nil
131 }
132133- var finalStreams []Livestream
134-135- // for each seg, put results in map if seg start time is after 30 seconds ago
136- for _, seg := range recentLivestreams {
137- layout := "2006-01-02 15:04:05.000+00:00"
138- segStartTime, _ := time.Parse(layout, seg.LatestSegmentStartTime)
139- if segStartTime.After(thirtySecondsAgo) {
140- finalStreams = append(finalStreams, seg.Livestream)
141- //fmt.Printf("seg start time: %s vs 30 seconds ago: %s\n", segStartTime, thirtySecondsAgo.UTC())
142- }
143- }
144-145- return finalStreams, nil
146}
···76 return &livestream, nil
77}
78000000079// GetLatestLivestreams returns the most recent livestreams, given a limit and a cursor
80// Only gets livestreams with a valid segment no less than 30 seconds old
81func (m *DBModel) GetLatestLivestreams(limit int, before *time.Time) ([]Livestream, error) {
82+ var recentLivestreams []Livestream
83 thirtySecondsAgo := time.Now().Add(-30 * time.Second)
8485 // get latest segment for the repo DID
···89 m.DB.Table("segments").
90 Select("repo_did, MAX(start_time)").
91 Group("repo_did")).
92+ Where("start_time > ?", thirtySecondsAgo.UTC()).
93 Group("repo_did")
9495 rankedLivestreamsSubQuery := m.DB.Table("livestreams").
···123 return nil, nil
124 }
125126+ return recentLivestreams, nil
000000000000127}