Skip to content

Instantly share code, notes, and snippets.

@jrallison
Created March 15, 2015 19:45
Show Gist options
  • Save jrallison/e1b62d90be52496b97ef to your computer and use it in GitHub Desktop.
Save jrallison/e1b62d90be52496b97ef to your computer and use it in GitHub Desktop.
Version A
package main
import (
"customerio/core/customers"
"customerio/core/segments"
"customerio/core/spaces"
"flag"
"log"
"strconv"
"time"
"github.com/FoundationDB/fdb-go/fdb"
)
var id = flag.Int("env", 0, "environment to check")
func main() {
flag.Parse()
var count int
var missing int
var blank int
env := segments.GetEnv(*id)
start := time.Now()
check := func(internals []string) {
spaces.LowPriorityTransact(spaces.Db(), func(tr fdb.Transaction) {
earliest := make(map[string]*customers.AttributeCommand)
for _, internal := range internals {
earliest[internal] = customers.NewAttributeCommand(env.Id, internal, "_earliest_event")
earliest[internal].Prefetch(tr)
}
for _, internal := range internals {
count += 1
attr := earliest[internal].Commit(tr)
if attr == "" {
blank += 1
}
if ts, err := strconv.Atoi(attr); err != nil || ts == 0 {
missing += 1
}
if count%1000 == 0 {
log.Println(count, missing, blank)
}
}
})
}
batch := make([]string, 0, 200)
customers.GetEnv(env.Id).EachInternal(0, "", func(internal string) bool {
batch = append(batch, internal)
if len(batch) >= 200 {
check(batch)
batch = make([]string, 0, 200)
}
return true
})
check(batch)
log.Println("checked in", time.Since(start), count, missing, blank)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment