Compare commits
No commits in common. "56a80d8936cadd67aa96f4ab7076da205f96b6b0" and "3966e6e226fb51ad80fe5038acf8fad0630d2ed9" have entirely different histories.
56a80d8936
...
3966e6e226
|
@ -9,7 +9,7 @@ FROM library/node:14.7.0-stretch AS frontend
|
|||
COPY build/react-frontend /frontend
|
||||
RUN cd /frontend; npm install && npm run build
|
||||
|
||||
FROM scratch
|
||||
FROM debian
|
||||
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
||||
COPY --from=builder /go/src/git.martyn.berlin/martyn/twitchsingstools /app/
|
||||
COPY web/ /app/web/
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
"math/rand"
|
||||
"regexp"
|
||||
"sort"
|
||||
"sync"
|
||||
"unicode"
|
||||
|
||||
irc "git.martyn.berlin/martyn/twitchsingstools/internal/irc"
|
||||
|
@ -236,8 +235,22 @@ func AdminHandler(response http.ResponseWriter, request *http.Request) {
|
|||
TopNSingers []SingerSings
|
||||
ChannelKey string
|
||||
}
|
||||
updateCacheIfNecessary(vars["channel"])
|
||||
channelData := ircBot.ChannelData[vars["channel"]]
|
||||
if time.Now().Sub(ircBot.ChannelData[vars["channel"]].VideoCacheUpdated).Hours() > 1 {
|
||||
fmt.Printf("Cache of %d performances is older than an hour - %.1f hours old to be precise... fetching.\n", len(ircBot.ChannelData[vars["channel"]].VideoCache), time.Now().Sub(ircBot.ChannelData[vars["channel"]].VideoCacheUpdated).Hours())
|
||||
vids, err := fetchAllVoDs(channelData.TwitchUserID, channelData.Bearer)
|
||||
if err != nil {
|
||||
errCache := make([]irc.SingsVideoStruct, 0)
|
||||
var ret irc.SingsVideoStruct
|
||||
ret.FullTitle = "Error fetching videos: " + err.Error()
|
||||
errCache = append(errCache, ret)
|
||||
vids = errCache
|
||||
}
|
||||
updateCalculatedFields(vids)
|
||||
ircBot.UpdateVideoCache(vars["channel"], vids)
|
||||
} else {
|
||||
fmt.Printf("Cache of %d performances is younger than an hour - %.1f hours old to be precise... not fetching.\n", len(ircBot.ChannelData[vars["channel"]].VideoCache), time.Now().Sub(ircBot.ChannelData[vars["channel"]].VideoCacheUpdated).Hours())
|
||||
}
|
||||
updateCalculatedFields(channelData.VideoCache)
|
||||
for _, song := range channelData.VideoCache {
|
||||
if song.Duet && song.OtherSinger == "" {
|
||||
|
@ -477,29 +490,6 @@ func (h *KVHeap) Pop() interface{} {
|
|||
return x
|
||||
}
|
||||
|
||||
var cacheLock sync.Mutex
|
||||
|
||||
func updateCacheIfNecessary(channel string) {
|
||||
cacheLock.Lock()
|
||||
channelData := ircBot.ChannelData[channel]
|
||||
if time.Now().Sub(channelData.VideoCacheUpdated).Hours() > 1 {
|
||||
fmt.Printf("Cache of %d performances is older than an hour - %.1f hours old to be precise... fetching.\n", len(channelData.VideoCache), time.Now().Sub(ircBot.ChannelData[channel].VideoCacheUpdated).Hours())
|
||||
vids, err := fetchAllVoDs(channelData.TwitchUserID, channelData.Bearer)
|
||||
if err != nil {
|
||||
errCache := make([]irc.SingsVideoStruct, 0)
|
||||
var ret irc.SingsVideoStruct
|
||||
ret.FullTitle = "Error fetching videos: " + err.Error()
|
||||
errCache = append(errCache, ret)
|
||||
vids = errCache
|
||||
}
|
||||
updateCalculatedFields(vids)
|
||||
ircBot.UpdateVideoCache(channel, vids)
|
||||
} else {
|
||||
fmt.Printf("Cache of %d performances is younger than an hour - %.1f hours old to be precise... not fetching.\n", len(channelData.VideoCache), time.Now().Sub(ircBot.ChannelData[channel].VideoCacheUpdated).Hours())
|
||||
}
|
||||
cacheLock.Unlock()
|
||||
}
|
||||
|
||||
func calculateTopNSingers(songCache []irc.SingsVideoStruct, howMany int) []SingerSings {
|
||||
songMap := map[string]int{}
|
||||
songCount := 0
|
||||
|
@ -756,8 +746,22 @@ func CSVHandler(response http.ResponseWriter, request *http.Request) {
|
|||
TopNSongs []SongSings
|
||||
TopNSingers []SingerSings
|
||||
}
|
||||
updateCacheIfNecessary(vars["channel"])
|
||||
channelData := ircBot.ChannelData[vars["channel"]]
|
||||
if time.Now().Sub(ircBot.ChannelData[vars["channel"]].VideoCacheUpdated).Hours() > 1 {
|
||||
fmt.Printf("Cache of %d performances is older than an hour - %.1f hours old to be precise... fetching.\n", len(ircBot.ChannelData[vars["channel"]].VideoCache), time.Now().Sub(ircBot.ChannelData[vars["channel"]].VideoCacheUpdated).Hours())
|
||||
vids, err := fetchAllVoDs(channelData.TwitchUserID, channelData.Bearer)
|
||||
if err != nil {
|
||||
errCache := make([]irc.SingsVideoStruct, 0)
|
||||
var ret irc.SingsVideoStruct
|
||||
ret.FullTitle = "Error fetching videos: " + err.Error()
|
||||
errCache = append(errCache, ret)
|
||||
vids = errCache
|
||||
}
|
||||
updateCalculatedFields(vids)
|
||||
ircBot.UpdateVideoCache(vars["channel"], vids)
|
||||
} else {
|
||||
fmt.Printf("Cache of %d performances is younger than an hour - %.1f hours old to be precise... not fetching.\n", len(ircBot.ChannelData[vars["channel"]].VideoCache), time.Now().Sub(ircBot.ChannelData[vars["channel"]].VideoCacheUpdated).Hours())
|
||||
}
|
||||
topNSongs := calculateTopNSongs(channelData.VideoCache, 10)
|
||||
topNSingers := calculateTopNSingers(channelData.VideoCache, 10)
|
||||
var td = TemplateData{channelData.Name, channelData.Command, channelData.ExtraStrings, channelData.JoinTime, channelData.JoinTime.Format(irc.UTCFormat), false, channelData.HasLeft, AugmentSingsVideoStructSliceForCSV(channelData.VideoCache), topNSongs, topNSingers}
|
||||
|
@ -792,8 +796,22 @@ func JSONHandler(response http.ResponseWriter, request *http.Request) {
|
|||
TopNSongs []SongSings
|
||||
TopNSingers []SingerSings
|
||||
}
|
||||
updateCacheIfNecessary(vars["channel"])
|
||||
channelData := ircBot.ChannelData[vars["channel"]]
|
||||
if time.Now().Sub(ircBot.ChannelData[vars["channel"]].VideoCacheUpdated).Hours() > 1 {
|
||||
fmt.Printf("Cache of %d performances is older than an hour - %.1f hours old to be precise... fetching.\n", len(ircBot.ChannelData[vars["channel"]].VideoCache), time.Now().Sub(ircBot.ChannelData[vars["channel"]].VideoCacheUpdated).Hours())
|
||||
vids, err := fetchAllVoDs(channelData.TwitchUserID, channelData.Bearer)
|
||||
if err != nil {
|
||||
errCache := make([]irc.SingsVideoStruct, 0)
|
||||
var ret irc.SingsVideoStruct
|
||||
ret.FullTitle = "Error fetching videos: " + err.Error()
|
||||
errCache = append(errCache, ret)
|
||||
vids = errCache
|
||||
}
|
||||
updateCalculatedFields(vids)
|
||||
ircBot.UpdateVideoCache(vars["channel"], vids)
|
||||
} else {
|
||||
fmt.Printf("Cache of %d performances is younger than an hour - %.1f hours old to be precise... not fetching.\n", len(ircBot.ChannelData[vars["channel"]].VideoCache), time.Now().Sub(ircBot.ChannelData[vars["channel"]].VideoCacheUpdated).Hours())
|
||||
}
|
||||
topNSongs := calculateTopNSongs(channelData.VideoCache, 10)
|
||||
topNSingers := calculateTopNSingers(channelData.VideoCache, 10)
|
||||
var td = TemplateData{channelData.Name, channelData.Command, channelData.ExtraStrings, channelData.JoinTime, channelData.JoinTime.Format(irc.UTCFormat), false, channelData.HasLeft, AugmentSingsVideoStructSlice(channelData.VideoCache), topNSongs, topNSingers}
|
||||
|
|
Loading…
Reference in New Issue