2021-08-07 17:13:10 +00:00
|
|
|
/*
|
|
|
|
* Wiki - A wiki with editor
|
|
|
|
* Copyright (c) 2021 Peter Stuifzand
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2019-03-03 07:30:04 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func combine(x, y Change) Change {
|
|
|
|
x.Count++
|
|
|
|
if x.Body == "" {
|
|
|
|
x.Body = y.Body
|
|
|
|
} else {
|
|
|
|
x.Body += " " + y.Body
|
|
|
|
}
|
|
|
|
x.EndDate = y.Date
|
|
|
|
|
|
|
|
return x
|
|
|
|
}
|
|
|
|
|
|
|
|
func changeEqual(x, y Change) bool {
|
|
|
|
return x.Page == y.Page && x.Date.Truncate(24*time.Hour) == y.Date.Truncate(24*time.Hour)
|
|
|
|
}
|
|
|
|
|
|
|
|
func groupRecentChanges(changes []Change) int {
|
|
|
|
if len(changes) <= 1 {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
f := len(changes) - 1
|
|
|
|
i := f - 1
|
|
|
|
|
|
|
|
for {
|
|
|
|
if changeEqual(changes[f], changes[i]) {
|
|
|
|
changes[f] = combine(changes[f], changes[i])
|
|
|
|
} else {
|
|
|
|
f--
|
2019-03-03 07:33:55 +00:00
|
|
|
changes[f] = changes[i]
|
2019-03-03 07:30:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if i <= 0 {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
i--
|
|
|
|
}
|
|
|
|
|
|
|
|
return f
|
|
|
|
}
|