//getFromList returns one node in the nodelist. func getFromList() *node.Node { var rs map[string]struct{} err := db.DB.View(func(tx *bolt.Tx) error { var err error rs, err = db.GetMap(tx, "lookupT", []byte(list)) return err }) if err != nil { log.Print(err) return nil } if len(rs) == 0 { log.Println("node not found") return nil } var r string for rr := range rs { r = rr break } n, err := node.New(r) if err != nil { log.Println(err) return nil } return n }
//Len returns # of usertags. func Len(thread string) int { var r map[string]struct{} err := db.DB.View(func(tx *bolt.Tx) error { var errr error r, errr = db.GetMap(tx, "usertag", []byte(thread)) return errr }) if err != nil { log.Print(err) return 0 } return len(r) }
func listLen(datfile string) int { var rs map[string]struct{} err := db.DB.View(func(tx *bolt.Tx) error { var err error rs, err = db.GetMap(tx, "lookupT", []byte(datfile)) return err }) if err != nil { log.Print(err, datfile) return 0 } return len(rs) }
//Set remove all tags and saves tag strings. func Set(thread string, tag []string) { err := db.DB.Update(func(tx *bolt.Tx) error { ts, err := db.GetMap(tx, "usertag", []byte(thread)) if err != nil { log.Println(err) } for t := range ts { err = db.DelMap(tx, "usertagTag", []byte(t), thread) if err != nil { return err } } if err := db.Del(tx, "usertag", []byte(thread)); err != nil { log.Println(err) } return AddTX(tx, thread, tag) }) if err != nil { log.Print(err) } }
//RemoveFromAllTable removes node n from all tables and return true if exists. //or returns false if not exists. func RemoveFromAllTable(n *node.Node) bool { err := db.DB.Update(func(tx *bolt.Tx) error { threads, err := db.GetMap(tx, "lookupA", []byte(n.Nodestr)) if err != nil { return err } err = db.Del(tx, "lookupA", []byte(n.Nodestr)) if err != nil { return err } for t := range threads { err := db.DelMap(tx, "lookupT", []byte(t), n.Nodestr) if err != nil { return err } } return nil }) if err != nil { log.Println(err) return false } return true }