From 46280fd97b7827d90fcc524053ad0cc5515f0ecd Mon Sep 17 00:00:00 2001 From: Justin Li Date: Fri, 6 Sep 2013 19:08:06 -0400 Subject: [PATCH] Embed *db.Sql into storage/gazelle --- server/stats_test.go | 2 +- storage/gazelle/flush.go | 2 +- storage/gazelle/gazelle.go | 7 ++++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/server/stats_test.go b/server/stats_test.go index 2bf1542..20bbedc 100644 --- a/server/stats_test.go +++ b/server/stats_test.go @@ -14,7 +14,7 @@ import ( "github.com/pushrax/chihaya/config" _ "github.com/pushrax/chihaya/cache/redis" - _ "github.com/pushrax/chihaya/storage/batter" + _ "github.com/pushrax/chihaya/storage/gazelle" ) func newTestServer() (*Server, error) { diff --git a/storage/gazelle/flush.go b/storage/gazelle/flush.go index e0753fd..d847d2d 100644 --- a/storage/gazelle/flush.go +++ b/storage/gazelle/flush.go @@ -43,7 +43,7 @@ func (c *Conn) flushTorrents() { "Seeders = VALUES(Seeders), Leechers = VALUES(Leechers), " + "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 { time.Sleep(200 * time.Millisecond) diff --git a/storage/gazelle/gazelle.go b/storage/gazelle/gazelle.go index 664fbeb..c5e21c9 100644 --- a/storage/gazelle/gazelle.go +++ b/storage/gazelle/gazelle.go @@ -35,7 +35,7 @@ func (d *driver) New(conf *config.DataStore) storage.Conn { } db.SetMaxIdleConns(conf.MaxIdleConns) - conn := &Conn{db: db} + conn := &Conn{DB: db} // TODO Buffer sizes conn.torrentChannel = make(chan string, 1000) @@ -48,7 +48,6 @@ func (d *driver) New(conf *config.DataStore) storage.Conn { } type Conn struct { - db *sql.DB waitGroup sync.WaitGroup terminate bool @@ -57,6 +56,8 @@ type Conn struct { transferHistoryChannel chan string transferIpsChannel chan string snatchChannel chan string + + *sql.DB } func (c *Conn) Start() error { @@ -71,7 +72,7 @@ func (c *Conn) Start() error { func (c *Conn) Close() error { c.terminate = true c.waitGroup.Wait() - return c.db.Close() + return c.DB.Close() } func (c *Conn) RecordAnnounce(delta *models.AnnounceDelta) error {