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

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
JustHumanz committed Jan 1, 2022
1 parent e3545a9 commit d17446f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 14 deletions.
44 changes: 31 additions & 13 deletions pkg/database/generaldb.go
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ func ChannelTag(MemberID int64, typetag int, Options string, Reg string) ([]Disc
if err != nil {
return nil, err
}
if len(val) == 0 {
if err == redis.Nil || len(val) == 0 {
if Options == "NotLiveOnly" {
rows, err = DB.Query(`Select Channel.id,DiscordChannelID,Dynamic,Lite,IndieNotif,VtuberGroup.id FROM Channel Inner join VtuberGroup on VtuberGroup.id = Channel.VtuberGroup_id inner Join VtuberMember on VtuberMember.VtuberGroup_id = VtuberGroup.id Where VtuberMember.id=? AND (Channel.type=2 OR Channel.type=3) AND LiveOnly=0 AND (Channel.Region like ? OR Channel.Region='')`, MemberID, "%"+Reg+"%")
if err != nil {
Expand Down Expand Up @@ -849,24 +849,42 @@ func GetUserReminderList(ChannelIDDiscord int64, Member int64, Reminder int) ([]
UserTagsList []string
DiscordUserID string
Type bool
Key = strconv.Itoa(int(ChannelIDDiscord)) + strconv.Itoa(int(Member)) + strconv.Itoa(int(Reminder))
rds = UserTagCache
ctx = context.Background()
)
rows, err := DB.Query(`SELECT DiscordID,Human From User WHERE Channel_id=? And VtuberMember_id=? And Reminder=?`, ChannelIDDiscord, Member, Reminder)
if err != nil {
return nil, err
}
defer rows.Close()

for rows.Next() {
err = rows.Scan(&DiscordUserID, &Type)
val2, err := rds.LRange(ctx, Key, 0, -1).Result()
if err == redis.Nil || len(val2) == 0 {
rows, err := DB.Query(`SELECT DiscordID,Human From User WHERE Channel_id=? And VtuberMember_id=? And Reminder=?`, ChannelIDDiscord, Member, Reminder)
if err != nil {
return nil, err
}
if Type {
UserTagsList = append(UserTagsList, "<@"+DiscordUserID+">")
} else {
UserTagsList = append(UserTagsList, "<@&"+DiscordUserID+">")
defer rows.Close()

for rows.Next() {
err = rows.Scan(&DiscordUserID, &Type)
if err != nil {
return nil, err
}
if Type {
UserTagsList = append(UserTagsList, "<@"+DiscordUserID+">")
} else {
UserTagsList = append(UserTagsList, "<@&"+DiscordUserID+">")
}
}
err = rds.LPush(ctx, Key, UserTagsList).Err()
if err != nil {
log.Error(err)
}

err = rds.Expire(ctx, Key, config.GetUserListTTL).Err()
if err != nil {
log.Error(err)
}
} else {
UserTagsList = val2
}

return UserTagsList, nil
}

Expand Down
7 changes: 6 additions & 1 deletion pkg/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,12 @@ func ParseInt64(value string) int64 {
}

func GetMaxSqlConn() int {
return int((int64(memory.FreeMemory()/1024/1024) * 1024 * 1024) / 12582880)
a := int((int64(memory.FreeMemory()/1024/1024) * 1024 * 1024) / 12582880)
//Avoid discord Rate Limit
if a > 100 {
return 100
}
return a
}

func InitTwitterScraper() *twitterscraper.Scraper {
Expand Down

0 comments on commit d17446f

Please sign in to comment.