Use strings for the database channels and add handling for torrents

This commit is contained in:
Justin Li 2013-09-06 18:51:15 -04:00
parent 080a24c7be
commit 4687ddde6f
2 changed files with 20 additions and 14 deletions

View file

@ -23,11 +23,11 @@ func (c *Conn) flushTorrents() {
query.WriteString("INSERT INTO torrents (ID, Snatched, Seeders, Leechers, last_action) VALUES\n") query.WriteString("INSERT INTO torrents (ID, Snatched, Seeders, Leechers, last_action) VALUES\n")
for count = 0; count < length; count++ { for count = 0; count < length; count++ {
b := <-c.torrentChannel s := <-c.torrentChannel
if b == nil { if s == "" {
break break
} }
query.Write(b.Bytes()) query.WriteString(s)
if count != length-1 { if count != length-1 {
query.WriteRune(',') query.WriteRune(',')

View file

@ -7,7 +7,6 @@
package gazelle package gazelle
import ( import (
"bytes"
"database/sql" "database/sql"
"fmt" "fmt"
"sync" "sync"
@ -39,11 +38,11 @@ func (d *driver) New(conf *config.DataStore) storage.Conn {
conn := &Conn{db: db} conn := &Conn{db: db}
// TODO Buffer sizes // TODO Buffer sizes
conn.torrentChannel = make(chan *bytes.Buffer, 1000) conn.torrentChannel = make(chan string, 1000)
conn.userChannel = make(chan *bytes.Buffer, 1000) conn.userChannel = make(chan string, 1000)
conn.transferHistoryChannel = make(chan *bytes.Buffer, 1000) conn.transferHistoryChannel = make(chan string, 1000)
conn.transferIpsChannel = make(chan *bytes.Buffer, 1000) conn.transferIpsChannel = make(chan string, 1000)
conn.snatchChannel = make(chan *bytes.Buffer, 100) conn.snatchChannel = make(chan string, 100)
return conn return conn
} }
@ -53,11 +52,11 @@ type Conn struct {
waitGroup sync.WaitGroup waitGroup sync.WaitGroup
terminate bool terminate bool
torrentChannel chan *bytes.Buffer torrentChannel chan string
userChannel chan *bytes.Buffer userChannel chan string
transferHistoryChannel chan *bytes.Buffer transferHistoryChannel chan string
transferIpsChannel chan *bytes.Buffer transferIpsChannel chan string
snatchChannel chan *bytes.Buffer snatchChannel chan string
} }
func (c *Conn) Start() error { func (c *Conn) Start() error {
@ -76,6 +75,13 @@ func (c *Conn) Close() error {
} }
func (c *Conn) RecordAnnounce(delta *models.AnnounceDelta) error { func (c *Conn) RecordAnnounce(delta *models.AnnounceDelta) error {
c.torrentChannel <- fmt.Sprintf(
"('%s','%s','%s','%s','%s')",
delta.Torrent.ID,
len(delta.Torrent.Seeders),
len(delta.Torrent.Leechers),
delta.Torrent.LastAction,
)
return nil return nil
} }