mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-03-30 04:03:18 +00:00
feat: implement caching for channel retrieval
This commit is contained in:
20
model/log.go
20
model/log.go
@@ -295,8 +295,24 @@ func GetAllLogs(logType int, startTimestamp int64, endTimestamp int64, modelName
|
||||
Id int `gorm:"column:id"`
|
||||
Name string `gorm:"column:name"`
|
||||
}
|
||||
if err = DB.Table("channels").Select("id, name").Where("id IN ?", channelIds.Items()).Find(&channels).Error; err != nil {
|
||||
return logs, total, err
|
||||
if common.MemoryCacheEnabled {
|
||||
// Cache get channel
|
||||
for _, channelId := range channelIds.Items() {
|
||||
if cacheChannel, err := CacheGetChannel(channelId); err == nil {
|
||||
channels = append(channels, struct {
|
||||
Id int `gorm:"column:id"`
|
||||
Name string `gorm:"column:name"`
|
||||
}{
|
||||
Id: channelId,
|
||||
Name: cacheChannel.Name,
|
||||
})
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Bulk query channels from DB
|
||||
if err = DB.Table("channels").Select("id, name").Where("id IN ?", channelIds.Items()).Find(&channels).Error; err != nil {
|
||||
return logs, total, err
|
||||
}
|
||||
}
|
||||
channelMap := make(map[int]string, len(channels))
|
||||
for _, channel := range channels {
|
||||
|
||||
Reference in New Issue
Block a user