Embed *db.Sql into storage/gazelle

This commit is contained in:
Justin Li 2013-09-06 19:08:06 -04:00
parent afa8abb9ab
commit 46280fd97b
3 changed files with 6 additions and 5 deletions

View file

@ -14,7 +14,7 @@ import (
"github.com/pushrax/chihaya/config" "github.com/pushrax/chihaya/config"
_ "github.com/pushrax/chihaya/cache/redis" _ "github.com/pushrax/chihaya/cache/redis"
_ "github.com/pushrax/chihaya/storage/batter" _ "github.com/pushrax/chihaya/storage/gazelle"
) )
func newTestServer() (*Server, error) { func newTestServer() (*Server, error) {

View file

@ -43,7 +43,7 @@ func (c *Conn) flushTorrents() {
"Seeders = VALUES(Seeders), Leechers = VALUES(Leechers), " + "Seeders = VALUES(Seeders), Leechers = VALUES(Leechers), " +
"last_action = IF(last_action < VALUES(last_action), VALUES(last_action), last_action);") "last_action = IF(last_action < VALUES(last_action), VALUES(last_action), last_action);")
c.db.Exec(query.String()) c.Exec(query.String())
if length < cap(c.torrentChannel)/2 { if length < cap(c.torrentChannel)/2 {
time.Sleep(200 * time.Millisecond) time.Sleep(200 * time.Millisecond)

View file

@ -35,7 +35,7 @@ func (d *driver) New(conf *config.DataStore) storage.Conn {
} }
db.SetMaxIdleConns(conf.MaxIdleConns) db.SetMaxIdleConns(conf.MaxIdleConns)
conn := &Conn{db: db} conn := &Conn{DB: db}
// TODO Buffer sizes // TODO Buffer sizes
conn.torrentChannel = make(chan string, 1000) conn.torrentChannel = make(chan string, 1000)
@ -48,7 +48,6 @@ func (d *driver) New(conf *config.DataStore) storage.Conn {
} }
type Conn struct { type Conn struct {
db *sql.DB
waitGroup sync.WaitGroup waitGroup sync.WaitGroup
terminate bool terminate bool
@ -57,6 +56,8 @@ type Conn struct {
transferHistoryChannel chan string transferHistoryChannel chan string
transferIpsChannel chan string transferIpsChannel chan string
snatchChannel chan string snatchChannel chan string
*sql.DB
} }
func (c *Conn) Start() error { func (c *Conn) Start() error {
@ -71,7 +72,7 @@ func (c *Conn) Start() error {
func (c *Conn) Close() error { func (c *Conn) Close() error {
c.terminate = true c.terminate = true
c.waitGroup.Wait() c.waitGroup.Wait()
return c.db.Close() return c.DB.Close()
} }
func (c *Conn) RecordAnnounce(delta *models.AnnounceDelta) error { func (c *Conn) RecordAnnounce(delta *models.AnnounceDelta) error {