0.1.38 gateway
This commit is contained in:
@@ -679,6 +679,10 @@ func (s *Server) heroRow(
|
||||
policy = store.HeroPolicy{}
|
||||
}
|
||||
pinned := s.pinnedHeroCandidates(ctx, policy.PinnedItemIDs)
|
||||
// Manual pins always lead. Schedules resolve on the gateway (never on a television),
|
||||
// then the existing automatic/release-aware selection fills any remaining places.
|
||||
scheduledIDs := activeHeroScheduleIDs(policy.Schedules, userID, now, location)
|
||||
scheduled := s.pinnedHeroCandidates(ctx, scheduledIDs)
|
||||
// Rank a pool, then draw the row out of it. Ranking straight to the row's length is
|
||||
// what made the hero the same four cards for a week — see rotateHeroCandidates.
|
||||
pool := rankHeroCandidates(candidates, now, heroPoolLimit)
|
||||
@@ -687,7 +691,7 @@ func (s *Server) heroRow(
|
||||
heroVariationSeed(userID, heroRotationSlot(now, location)),
|
||||
heroRowLimit,
|
||||
)
|
||||
ranked := mergePinnedHeroCandidates(pinned, candidates, organic, heroRowLimit)
|
||||
ranked := mergePinnedHeroCandidates(append(pinned, scheduled...), candidates, organic, heroRowLimit)
|
||||
if len(ranked) == 0 {
|
||||
return nil
|
||||
}
|
||||
@@ -746,6 +750,45 @@ func mergePinnedHeroCandidates(
|
||||
return out
|
||||
}
|
||||
|
||||
func activeHeroScheduleIDs(schedules []store.HeroSchedule, userID string, now time.Time, location *time.Location) []string {
|
||||
type active struct {
|
||||
id string
|
||||
priority int
|
||||
start time.Time
|
||||
}
|
||||
matched := []active{}
|
||||
for _, schedule := range schedules {
|
||||
if !schedule.Enabled || (schedule.UserID != "" && schedule.UserID != userID) || now.Before(schedule.StartAt) || !now.Before(schedule.EndAt) {
|
||||
continue
|
||||
}
|
||||
if len(schedule.Weekdays) > 0 {
|
||||
weekday := int(now.In(location).Weekday())
|
||||
found := false
|
||||
for _, day := range schedule.Weekdays {
|
||||
if day == weekday {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
continue
|
||||
}
|
||||
}
|
||||
matched = append(matched, active{schedule.ItemID, schedule.Priority, schedule.StartAt})
|
||||
}
|
||||
sort.SliceStable(matched, func(i, j int) bool {
|
||||
if matched[i].priority != matched[j].priority {
|
||||
return matched[i].priority > matched[j].priority
|
||||
}
|
||||
return matched[i].start.After(matched[j].start)
|
||||
})
|
||||
ids := make([]string, 0, len(matched))
|
||||
for _, item := range matched {
|
||||
ids = append(ids, item.id)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
// pinnedHeroCandidates resolves policy against the imported catalogue. A deleted or
|
||||
// unsupported id quietly drops out, so an old admin choice can never make Home fail.
|
||||
func (s *Server) pinnedHeroCandidates(ctx context.Context, ids []string) []heroCandidate {
|
||||
|
||||
Reference in New Issue
Block a user