summaryrefslogtreecommitdiff
path: root/rddb
diff options
context:
space:
mode:
Diffstat (limited to 'rddb')
-rw-r--r--rddb/rddb.go126
1 files changed, 83 insertions, 43 deletions
diff --git a/rddb/rddb.go b/rddb/rddb.go
index 847e865..d6cd2d3 100644
--- a/rddb/rddb.go
+++ b/rddb/rddb.go
@@ -101,6 +101,24 @@ type getMusicInfoRequest struct {
response chan<- getMusicInfoResult
}
+type ShowListEntry struct {
+ ID uint
+ Title string
+ log string
+ lowCart int
+ highCart int
+}
+
+type getShowListResult struct {
+ shows []ShowListEntry
+ err error
+}
+
+type getShowListRequest struct {
+ username string
+ response chan<- getShowListResult
+}
+
type CutListEntry struct {
Number uint
Evergreen bool
@@ -115,23 +133,17 @@ type CartListEntry struct {
Number uint
Exists bool
Title string
- Cuts []*CutListEntry
+ Cuts []CutListEntry
}
-type ShowListEntry struct {
- ID uint
- Title string
- Carts []*CartListEntry
-}
-
-type getShowListResult struct {
- shows []ShowListEntry
+type getShowCartListResult struct {
+ carts []CartListEntry
err error
}
-type getShowListRequest struct {
- username string
- response chan<- getShowListResult
+type getShowCartListRequest struct {
+ show ShowListEntry
+ response chan<- getShowCartListResult
}
type DB struct {
@@ -150,6 +162,7 @@ type DB struct {
getMusicInfoStmt *sql.Stmt
getShowListChan chan getShowListRequest
getShowListStmt *sql.Stmt
+ getShowCartListChan chan getShowCartListRequest
getCartInfoStmt *sql.Stmt
getCutInfoStmt *sql.Stmt
quit chan bool
@@ -190,7 +203,7 @@ func (db *DB) init() (err error) {
if db.getMusicInfoStmt, err = db.dbh.Prepare("select NORMALIZATION_LEVEL,AUTOTRIM_LEVEL from DROPBOXES where DROPBOXES.GROUP_NAME = ?;"); err != nil {
return
}
- if db.getShowListStmt, err = db.dbh.Prepare("select CART.TITLE,CART.MACROS,DROPBOXES.TO_CART,DROPBOXES.SET_USER_DEFINED,GROUPS.DEFAULT_LOW_CART,GROUPS.DEFAULT_HIGH_CART,GROUPS.DESCRIPTION from CART, USER_PERMS, DROPBOXES, GROUPS where CART.NUMBER = DROPBOXES.TO_CART and USER_PERMS.USER_NAME = ? and DROPBOXES.GROUP_NAME = USER_PERMS.GROUP_NAME and DROPBOXES.GROUP_NAME = GROUPS.NAME and DROPBOXES.STATION_NAME = ?;"); err != nil {
+ if db.getShowListStmt, err = db.dbh.Prepare("select CART.TITLE,CART.MACROS,DROPBOXES.TO_CART,DROPBOXES.SET_USER_DEFINED,GROUPS.DEFAULT_LOW_CART,GROUPS.DEFAULT_HIGH_CART from CART, USER_PERMS, DROPBOXES, GROUPS where CART.NUMBER = DROPBOXES.TO_CART and USER_PERMS.USER_NAME = ? and DROPBOXES.GROUP_NAME = USER_PERMS.GROUP_NAME and DROPBOXES.GROUP_NAME = GROUPS.NAME and DROPBOXES.STATION_NAME = ?;"); err != nil {
return
}
if db.getCartInfoStmt, err = db.dbh.Prepare("select TITLE from CART where TYPE=1 and NUMBER = ?"); err != nil {
@@ -322,7 +335,28 @@ func (db *DB) getMusicInfo(group string) (result getMusicInfoResult) {
return
}
-func (db *DB) getCutInfo(cart uint) (cuts []*CutListEntry, err error) {
+func (db *DB) getShowList(username string) (result getShowListResult) {
+ var rows *sql.Rows
+ if rows, result.err = db.getShowListStmt.Query(username, dropboxPseudoStation); result.err != nil {
+ return
+ }
+ defer rows.Close()
+
+ for rows.Next() {
+ var show ShowListEntry
+ var macros, params string
+
+ if result.err = rows.Scan(&show.Title, &macros, &show.ID, &params, &show.lowCart, &show.highCart); result.err != nil {
+ return
+ }
+ show.log = showMacroRe.FindStringSubmatch(macros)[1]
+ result.shows = append(result.shows, show)
+ }
+ result.err = rows.Err()
+ return
+}
+
+func (db *DB) getCutInfo(cart uint) (cuts []CutListEntry, err error) {
var rows *sql.Rows
if rows, err = db.getCutInfoStmt.Query(cart); err != nil {
return
@@ -330,7 +364,7 @@ func (db *DB) getCutInfo(cart uint) (cuts []*CutListEntry, err error) {
defer rows.Close()
for rows.Next() {
- var cut = &CutListEntry{}
+ var cut = CutListEntry{}
var cutName, evergreen string
var length uint
@@ -363,8 +397,8 @@ func (db *DB) getCutInfo(cart uint) (cuts []*CutListEntry, err error) {
return
}
-func (db *DB) getCartInfo(cart uint) (c *CartListEntry, err error) {
- c = &CartListEntry{}
+func (db *DB) getCartInfo(cart uint) (c CartListEntry, err error) {
+ c = CartListEntry{}
c.Number = cart
c.Exists = true
err = db.getCartInfoStmt.QueryRow(cart).Scan(&c.Title)
@@ -381,38 +415,19 @@ func (db *DB) getCartInfo(cart uint) (c *CartListEntry, err error) {
return
}
-func (db *DB) getShowList(username string) (result getShowListResult) {
- var rows *sql.Rows
- if rows, result.err = db.getShowListStmt.Query(username, dropboxPseudoStation); result.err != nil {
+func (db *DB) getShowCartList(show ShowListEntry) (result getShowCartListResult) {
+ var carts []uint
+ if carts, result.err = db.getShowCarts(show.log, show.lowCart, show.highCart); result.err != nil {
return
}
- defer rows.Close()
-
- for rows.Next() {
- var show ShowListEntry
- var macros, params, desc string
- var lowCart, highCart int
-
- if result.err = rows.Scan(&show.Title, &macros, &show.ID, &params, &lowCart, &highCart, &desc); result.err != nil {
- return
- }
- var carts []uint
- if carts, result.err = db.getShowCarts(showMacroRe.FindStringSubmatch(macros)[1], lowCart, highCart); result.err != nil {
+ for _, cart := range carts {
+ var c CartListEntry
+ if c, result.err = db.getCartInfo(cart); result.err != nil {
return
}
-
- for _, cart := range carts {
- var c *CartListEntry
- if c, result.err = db.getCartInfo(cart); result.err != nil {
- return
- }
- show.Carts = append(show.Carts, c)
- }
-
- result.shows = append(result.shows, show)
+ result.carts = append(result.carts, c)
}
- result.err = rows.Err()
return
}
@@ -434,6 +449,8 @@ func (db *DB) dispatchRequests() {
req.response <- db.getMusicInfo(req.group)
case req := <-db.getShowListChan:
req.response <- db.getShowList(req.username)
+ case req := <-db.getShowCartListChan:
+ req.response <- db.getShowCartList(req.show)
}
}
}
@@ -448,6 +465,7 @@ type DBChan struct {
checkMusicGroupChan chan<- checkMusicGroupRequest
getMusicInfoChan chan<- getMusicInfoRequest
getShowListChan chan<- getShowListRequest
+ getShowCartListChan chan<- getShowCartListRequest
}
func (db *DBChan) GetPassword(username string, cached bool) (string, error) {
@@ -562,6 +580,20 @@ func (db *DBChan) GetShowList(username string) ([]ShowListEntry, error) {
return res.shows, nil
}
+func (db *DBChan) GetShowCartList(show ShowListEntry) ([]CartListEntry, error) {
+ resCh := make(chan getShowCartListResult)
+ req := getShowCartListRequest{}
+ req.show = show
+ req.response = resCh
+ db.getShowCartListChan <- req
+
+ res := <-resCh
+ if res.err != nil {
+ return nil, res.err
+ }
+ return res.carts, nil
+}
+
func (db *DB) GetInterface() *DBChan {
ch := &DBChan{}
ch.getPasswordChan = db.getPasswordChan
@@ -570,6 +602,7 @@ func (db *DB) GetInterface() *DBChan {
ch.checkMusicGroupChan = db.checkMusicGroupChan
ch.getMusicInfoChan = db.getMusicInfoChan
ch.getShowListChan = db.getShowListChan
+ ch.getShowCartListChan = db.getShowCartListChan
return ch
}
@@ -600,6 +633,12 @@ func (db *DB) Cleanup() {
if db.getShowListStmt != nil {
db.getShowListStmt.Close()
}
+ if db.getCartInfoStmt != nil {
+ db.getCartInfoStmt.Close()
+ }
+ if db.getCutInfoStmt != nil {
+ db.getCutInfoStmt.Close()
+ }
}
func NewDB(configfile string) (db *DB, err error) {
@@ -616,6 +655,7 @@ func NewDB(configfile string) (db *DB, err error) {
db.checkMusicGroupChan = make(chan checkMusicGroupRequest, 10)
db.getMusicInfoChan = make(chan getMusicInfoRequest, 10)
db.getShowListChan = make(chan getShowListRequest, 10)
+ db.getShowCartListChan = make(chan getShowCartListRequest, 10)
if err = db.init(); err != nil {
return