mirror of
https://github.com/schollz/cowyo.git
synced 2023-08-10 21:13:00 +03:00
Faster versioning
Former-commit-id: c16b386fb5649469554fa0c524da25a96f847b1c [formerly c720f4fe0bad6b5cdcdbf2ca5ebce0455f00c0c2] [formerly 17516532eebffed40114514481265e609d36ca45 [formerly 011bbba9eb
]]
Former-commit-id: c62552a2564a20eaa2bb29d8fe73597f9bcc1538 [formerly afd5541621b6cc04e9f4a311f95f1f6763dfc3a4]
Former-commit-id: 5c3bc27d7dff61fea4f7d1634d6a5c13ec17bba2
This commit is contained in:
parent
cc4f2b58ef
commit
9d3ed7917b
15
utils.go
15
utils.go
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
@ -107,15 +108,16 @@ func diffRebuildtexts(diffs []diffmatchpatch.Diff) []string {
|
|||||||
return text
|
return text
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func timeTrack(start time.Time, name string) {
|
||||||
|
elapsed := time.Since(start)
|
||||||
|
log.Printf("%s took %s", name, elapsed)
|
||||||
|
}
|
||||||
|
|
||||||
func getImportantVersions(p WikiData) []versionsInfo {
|
func getImportantVersions(p WikiData) []versionsInfo {
|
||||||
|
defer timeTrack(time.Now(), "getImportantVersions")
|
||||||
m := map[int]int{}
|
m := map[int]int{}
|
||||||
dmp := diffmatchpatch.New()
|
|
||||||
lastText := ""
|
|
||||||
lastTime := time.Now().AddDate(0, -1, 0)
|
lastTime := time.Now().AddDate(0, -1, 0)
|
||||||
for i, diff := range p.Diffs {
|
for i, _ := range p.Diffs {
|
||||||
seq1, _ := dmp.DiffFromDelta(lastText, diff)
|
|
||||||
texts_linemode := diffRebuildtexts(seq1)
|
|
||||||
rebuilt := texts_linemode[len(texts_linemode)-1]
|
|
||||||
parsedTime, _ := time.Parse(time.ANSIC, p.Timestamps[i])
|
parsedTime, _ := time.Parse(time.ANSIC, p.Timestamps[i])
|
||||||
duration := parsedTime.Sub(lastTime)
|
duration := parsedTime.Sub(lastTime)
|
||||||
m[i] = int(duration.Seconds())
|
m[i] = int(duration.Seconds())
|
||||||
@ -123,7 +125,6 @@ func getImportantVersions(p WikiData) []versionsInfo {
|
|||||||
m[i-1] = m[i]
|
m[i-1] = m[i]
|
||||||
}
|
}
|
||||||
// On to the next one
|
// On to the next one
|
||||||
lastText = rebuilt
|
|
||||||
lastTime = parsedTime
|
lastTime = parsedTime
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user