Skip to content

Commit cfafcc7

Browse files
committed
fix: Replace the oldest history record with the latest one.
1 parent 1d71722 commit cfafcc7

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

pkg/server.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,17 @@ func (s *dbserver) CreateTestCaseHistory(ctx context.Context, historyTestResult
251251
db.Model(&HistoryTestResult{}).Count(&count)
252252

253253
if count >= int64(historyLimit) {
254-
fmt.Printf("Existing count: %d, limit: %d\nmaximum number of entries reached, cannot create new TestCaseHistory\n", count, historyLimit)
255-
return
254+
var oldestRecord HistoryTestResult
255+
if err = db.Order("create_time").First(&oldestRecord).Error; err != nil {
256+
fmt.Printf("Error find oldest record: %v\n", err)
257+
return
258+
}
259+
260+
if err = db.Delete(&oldestRecord).Error; err != nil {
261+
fmt.Printf("Error delete oldest record: %v\n", err)
262+
return
263+
}
264+
fmt.Printf("Existing count: %d, limit: %d\nmaximum number of entries reached.\n", count, historyLimit)
256265
}
257266

258267
db.Create(ConvertToDBHistoryTestResult(historyTestResult))

0 commit comments

Comments
 (0)