@@ -65,13 +65,13 @@ type Log struct {
6565 Content EmptyNullString `gorm:"type:text" json:"content,omitempty"`
6666 GroupID string `json:"group,omitempty"`
6767 Model string `json:"model"`
68- RequestID EmptyNullString `gorm:"index" json:"request_id"`
68+ RequestID EmptyNullString `gorm:"index:,where:request_id is not null" json:"request_id"`
6969 ID int `gorm:"primaryKey" json:"id"`
7070 TokenID int `gorm:"index" json:"token_id,omitempty"`
7171 ChannelID int `json:"channel,omitempty"`
7272 Code int `gorm:"index" json:"code,omitempty"`
7373 Mode int `json:"mode,omitempty"`
74- IP EmptyNullString `gorm:"index" json:"ip,omitempty"`
74+ IP EmptyNullString `gorm:"index:,where:ip is not null" json:"ip,omitempty"`
7575 RetryTimes ZeroNullInt64 `json:"retry_times,omitempty"`
7676 DownstreamResult bool `json:"downstream_result,omitempty"`
7777 Price Price `gorm:"embedded" json:"price,omitempty"`
@@ -264,9 +264,9 @@ func cleanLog(batchSize int, optimize bool) error {
264264 Model (& Log {}).
265265 Where (
266266 "created_at < ?" ,
267- time .Now ().Add (- time .Duration (logContentStorageHours )* time .Hour ),
267+ time .Now ().Truncate ( time . Hour ). Add (- time .Duration (logContentStorageHours )* time .Hour ),
268268 ).
269- Where ("endpoint IS NOT NULL OR ip IS NOT NULL OR content IS NOT NULL OR ttfb_milliseconds IS NOT NULL " ).
269+ Where ("endpoint IS NOT NULL" ).
270270 Order ("created_at DESC" ).
271271 Limit (1 ).
272272 Select ("id" ).
@@ -282,7 +282,7 @@ func cleanLog(batchSize int, optimize bool) error {
282282 Model (& Log {}).
283283 Session (& gorm.Session {SkipDefaultTransaction : true }).
284284 Where (
285- "id BETWEEN ? AND ?" ,
285+ "id BETWEEN ? AND ? AND content IS NOT NULL " ,
286286 id - int64 (batchSize ),
287287 id ,
288288 ).
0 commit comments