func LinkBench() { var db = loge.NewLogeDB(loge.NewLevelDBStore("data/linkbench")) defer db.Close() db.CreateType(loge.NewTypeDef("person", 1, &Person{})) var petDef = loge.NewTypeDef("pet", 1, &Pet{}) petDef.Links = loge.LinkSpec{"owner": "person"} db.CreateType(petDef) fmt.Printf("Inserting...\n") db.Transact(func(t *loge.Transaction) { t.Set("person", "Brendon", &Person{"Brendon", 31, []uint16{}}) for i := 0; i < 10000; i++ { var key = fmt.Sprintf("pet-%04d", i) t.Set("pet", loge.LogeKey(key), &Pet{key, "dog"}) t.AddLink("pet", "owner", loge.LogeKey(key), "Brendon") } }, 0) fmt.Printf("Finding...\n") var count = 0 db.Transact(func(t *loge.Transaction) { var pets = t.Find("pet", "owner", "Brendon") for pets.Valid() { pets.Next() count++ } }, 0) fmt.Printf("Found %d pets\n", count) count = 0 var lastPet loge.LogeKey = "" var loops = 0 for loops < 1000 { db.Transact(func(t *loge.Transaction) { var somePets = t.FindSlice("pet", "owner", "Brendon", lastPet, 100) for somePets.Valid() { lastPet = somePets.Next() count++ } }, 0) loops++ } fmt.Printf("Sliced %d pets\n", count) }
func WritePeopleBatch(db *loge.LogeDB, start int, end int, tokens chan bool) { db.Transact(func(t *loge.Transaction) { fmt.Printf("Writing batch %d => %d\n", start, end) for i := start; i <= end; i++ { var name = fmt.Sprintf("Person %d", i) var person = Person{ Name: name, Age: uint32(i), } t.Set("person", loge.LogeKey(name), &person) } }, 0) tokens <- true }