Skip to content

Commit 0dc7e5c

Browse files
authored
Fix a flaw in keepLimitedContentHistory
Fix a flaw in keepLimitedContentHistory, the first and the last should never be deleted
1 parent 8ab05a0 commit 0dc7e5c

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

models/issues/content_history.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,16 @@ func keepLimitedContentHistory(e db.Engine, issueID, commentID int64, limit int)
7575
log.Error("can not query content history for deletion, err=%v", err)
7676
return
7777
}
78-
if len(res) <= 1 {
78+
if len(res) <= 2 {
7979
return
8080
}
8181

8282
outDatedCount := len(res) - limit
8383
for outDatedCount > 0 {
8484
var indexToDelete int
8585
minEditedInterval := -1
86-
// find a history revision with minimal edited interval to delete
87-
for i := 1; i < len(res); i++ {
86+
// find a history revision with minimal edited interval to delete, the first and the last should never be deleted
87+
for i := 1; i < len(res)-1; i++ {
8888
editedInterval := int(res[i].EditedUnix - res[i-1].EditedUnix)
8989
if minEditedInterval == -1 || editedInterval < minEditedInterval {
9090
minEditedInterval = editedInterval

0 commit comments

Comments
 (0)