Пример #1
0
func WriteDbSignature(db core.Database, d chan *core.Torrent, totalRows int64) {
	start := time.Now()
	count := int64(0)
	open := true
	b := make([]*core.Torrent, 0)
	k, err := crypto.NewKey()
	if err != nil {
		panic(err)
	}
	for open {
		b = b[:0]
		for i := 0; i < 100 && open; i++ {
			var t *core.Torrent
			t, open = <-d
			if !open {
				log.Println("Finished import! Imported", count, "rows.")
				return
			}
			b = append(b, t)
		}
		count += int64(len(b))
		s, err := core.SignTorrents(k, b)
		if err != nil {
			panic(err)
		}
		db.AddSignature(s)
		if count%10000 == 0 {
			eta := time.Now().Sub(start) / time.Duration(count) * time.Duration(totalRows-count)
			log.Println("Signed: ", count, "of", totalRows, "(ETA:", eta.String()+")")
		}
	}
}
Пример #2
0
func NumTorrents(d core.Database) int {
	c := make(chan string)
	go d.GetTorrents(c)
	count := 0
	for range c {
		count += 1
	}
	return count
}
Пример #3
0
func WriteDbTorrent(db core.Database, c chan *core.Torrent, totalRows int64) {
	start := time.Now()
	count := int64(0)
	for t := range c {
		count++
		db.Add(t)
		if count%10000 == 0 {
			eta := time.Now().Sub(start) / time.Duration(count) * time.Duration(totalRows-count)
			log.Println("Loaded: ", count, "of", totalRows, "(ETA:", eta.String()+")")
		}
	}
}