Skip to content
This repository was archived by the owner on Jan 31, 2023. It is now read-only.

Commit 4eea3d8

Browse files
committed
Fix remove cacheing
1 parent 2cff64e commit 4eea3d8

2 files changed

Lines changed: 13 additions & 44 deletions

File tree

pkg/database/generaldb.go

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"regexp"
99
"strconv"
1010
"strings"
11-
"time"
1211

1312
config "github.com/JustHumanz/Go-Simp/pkg/config"
1413
"github.com/go-redis/redis/v8"
@@ -913,47 +912,14 @@ func (i *LiveStream) RemoveCache(Key string, drop bool) error {
913912
ctx := context.Background()
914913

915914
if !drop {
916-
OldKey := Key + "-old"
917915
log.WithFields(log.Fields{
918916
"Key": Key,
919917
"VideoID": i.VideoID,
920-
"OldKey": OldKey,
921-
}).Info("Reslice Cache")
922-
//Yt
923-
val, err := LiveCache.LRange(ctx, Key, 0, -1).Result()
918+
}).Info("Remove cache from list")
919+
err := LiveCache.LRem(ctx, Key, 0, i).Err()
924920
if err != nil {
925921
return err
926922
}
927-
928-
var Data []LiveStream
929-
for _, result := range unique(val) {
930-
var list LiveStream
931-
err := json.Unmarshal([]byte(result), &list)
932-
if err != nil {
933-
return err
934-
}
935-
Data = append(Data, list)
936-
}
937-
938-
err = LiveCache.Rename(ctx, Key, OldKey).Err()
939-
if err != nil {
940-
return err
941-
}
942-
943-
err = LiveCache.Expire(ctx, OldKey, 5*time.Minute).Err()
944-
if err != nil {
945-
return err
946-
}
947-
948-
for _, v := range Data {
949-
if v.VideoID == i.VideoID {
950-
continue
951-
}
952-
err = LiveCache.LPush(ctx, Key, v).Err()
953-
if err != nil {
954-
return err
955-
}
956-
}
957923
} else {
958924
log.WithFields(log.Fields{
959925
"Key": Key,

service/livestream/youtube/counter/counter.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ type checkYtJob struct {
9797
}
9898

9999
func (i *checkYtJob) Run() {
100+
var RemovedCache []database.LiveStream
100101
for _, Group := range *GroupPayload {
101102
YoutubeStatus, Key, err := database.YtGetStatus(map[string]interface{}{
102103
"GroupID": Group.ID,
@@ -138,6 +139,7 @@ func (i *checkYtJob) Run() {
138139
}
139140

140141
Youtube.UpdateYt(config.LiveStatus)
142+
RemovedCache = append(RemovedCache, Youtube)
141143
return
142144
}
143145
log.WithFields(log.Fields{
@@ -153,10 +155,7 @@ func (i *checkYtJob) Run() {
153155
}
154156
if len(Data.Items) > 0 {
155157
if Data.Items[0].Snippet.VideoStatus != "none" {
156-
err = Youtube.RemoveCache(Key, false)
157-
if err != nil {
158-
log.Panic(err)
159-
}
158+
RemovedCache = append(RemovedCache, Youtube)
160159

161160
if Data.Items[0].Statistics.ViewCount != "" {
162161
Youtube.UpdateViewers(Data.Items[0].Statistics.ViewCount)
@@ -207,10 +206,7 @@ func (i *checkYtJob) Run() {
207206
Youtube.UpdateYt(config.PrivateStatus)
208207
}
209208
} else if Data.Items[0].Snippet.VideoStatus == "none" {
210-
err = Youtube.RemoveCache(Key, false)
211-
if err != nil {
212-
log.Panic(err)
213-
}
209+
RemovedCache = append(RemovedCache, Youtube)
214210

215211
if Data.Items[0].Statistics.ViewCount != "" {
216212
Youtube.UpdateViewers(Data.Items[0].Statistics.ViewCount)
@@ -266,7 +262,14 @@ func (i *checkYtJob) Run() {
266262
}
267263
}(Y, &i.wg)
268264
}
265+
269266
i.wg.Wait()
267+
for _, v := range RemovedCache {
268+
err := v.RemoveCache(Key, false)
269+
if err != nil {
270+
log.Error(err)
271+
}
272+
}
270273
}
271274
}
272275

0 commit comments

Comments
 (0)