From 9b3993f477eb8c1aafa34ae43106b9a76e4f684f Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Wed, 10 Feb 2016 15:38:55 -0500 Subject: [PATCH] Faster versioning Former-commit-id: c16b386fb5649469554fa0c524da25a96f847b1c [formerly c720f4fe0bad6b5cdcdbf2ca5ebce0455f00c0c2] [formerly 17516532eebffed40114514481265e609d36ca45 [formerly 1b8565dee8c4087486e74f2ede374e243bdf35f7 [formerly 011bbba9ebcb8da3336655702da3aa20e7169469]]] Former-commit-id: c62552a2564a20eaa2bb29d8fe73597f9bcc1538 [formerly afd5541621b6cc04e9f4a311f95f1f6763dfc3a4] Former-commit-id: 5c3bc27d7dff61fea4f7d1634d6a5c13ec17bba2 Former-commit-id: 9d3ed7917bc766495e99337f21972520a86091e2 --- utils.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/utils.go b/utils.go index 3515297..5b46f30 100644 --- a/utils.go +++ b/utils.go @@ -1,6 +1,7 @@ package main import ( + "log" "math/rand" "sort" "strings" @@ -107,15 +108,16 @@ func diffRebuildtexts(diffs []diffmatchpatch.Diff) []string { 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 { + defer timeTrack(time.Now(), "getImportantVersions") m := map[int]int{} - dmp := diffmatchpatch.New() - lastText := "" lastTime := time.Now().AddDate(0, -1, 0) - for i, diff := range p.Diffs { - seq1, _ := dmp.DiffFromDelta(lastText, diff) - texts_linemode := diffRebuildtexts(seq1) - rebuilt := texts_linemode[len(texts_linemode)-1] + for i, _ := range p.Diffs { parsedTime, _ := time.Parse(time.ANSIC, p.Timestamps[i]) duration := parsedTime.Sub(lastTime) m[i] = int(duration.Seconds()) @@ -123,7 +125,6 @@ func getImportantVersions(p WikiData) []versionsInfo { m[i-1] = m[i] } // On to the next one - lastText = rebuilt lastTime = parsedTime }