Исправлено кэширование оффлайн плейлистов
This commit is contained in:
@@ -146,6 +146,7 @@ func CheckPlaylists(lists []playlist.Playlist) (int, int) {
|
||||
if err != nil {
|
||||
log.Printf("Cannot read playlist [%s]: %s\n", pls.Url, err)
|
||||
offlineCount++
|
||||
cachePlaylist(pls)
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -156,28 +157,30 @@ func CheckPlaylists(lists []playlist.Playlist) (int, int) {
|
||||
|
||||
log.Printf("Parsed, checking channels (%d)...\n", len(pls.Channels))
|
||||
pls = CheckChannels(pls)
|
||||
|
||||
lists[idx] = pls
|
||||
|
||||
if app.Config.Cache.IsActive {
|
||||
jsonBytes, err := json.Marshal(pls)
|
||||
if err != nil {
|
||||
log.Printf("Error while saving playlist to cache: %s", err)
|
||||
}
|
||||
|
||||
ttl := time.Duration(app.Config.Cache.Ttl) * time.Second
|
||||
written := app.Cache.Set(ctx, pls.Code, string(jsonBytes), ttl)
|
||||
if written.Err() != nil {
|
||||
log.Printf("Error while saving playlist to cache: %s", err)
|
||||
}
|
||||
|
||||
log.Println("Cached sucessfully")
|
||||
}
|
||||
cachePlaylist(pls)
|
||||
}
|
||||
|
||||
return onlineCount, offlineCount
|
||||
}
|
||||
|
||||
func cachePlaylist(pls playlist.Playlist) {
|
||||
if app.Config.Cache.IsActive {
|
||||
jsonBytes, err := json.Marshal(pls)
|
||||
if err != nil {
|
||||
log.Printf("Error while saving playlist to cache: %s", err)
|
||||
}
|
||||
|
||||
ttl := time.Duration(app.Config.Cache.Ttl) * time.Second
|
||||
written := app.Cache.Set(ctx, pls.Code, string(jsonBytes), ttl)
|
||||
if written.Err() != nil {
|
||||
log.Printf("Error while saving playlist to cache: %s", err)
|
||||
}
|
||||
|
||||
log.Println("Cached sucessfully")
|
||||
}
|
||||
}
|
||||
|
||||
// CheckChannels проверяет каналы и возвращает их же с результатами проверки
|
||||
func CheckChannels(pls playlist.Playlist) playlist.Playlist {
|
||||
type errorData struct {
|
||||
|
||||
Reference in New Issue
Block a user