summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2015-12-26 09:52:33 (GMT)
committerChristian Pointner <equinox@helsinki.at>2015-12-26 09:52:33 (GMT)
commitfb26578868ae72ac636c8f5b286b968bfce4aa0e (patch)
tree1102a683a7dd73a71c485aadd78e4b922fb8ee62
parente2dee26e41817302ed4e14207ce779d58004f797 (diff)
small refactoring
-rw-r--r--importer.go72
-rw-r--r--rddb.go73
2 files changed, 80 insertions, 65 deletions
diff --git a/importer.go b/importer.go
index 7ce4033..28ca55a 100644
--- a/importer.go
+++ b/importer.go
@@ -142,84 +142,28 @@ func (ctx *ImportContext) SanityCheck() error {
}
func (ctx *ImportContext) getPassword(cached bool) (err error) {
- res_ch := make(chan getPasswordResult)
- req := getPasswordRequest{}
- req.username = ctx.UserName
- req.cached = cached
- req.response = res_ch
- ctx.rddb.getPasswordChan <- req
-
- res := <-res_ch
- if res.err != nil {
- return res.err
- }
- ctx.Password = res.password
- return nil
+ ctx.Password, err = ctx.rddb.GetPassword(ctx.UserName, cached)
+ return
}
-func (ctx *ImportContext) getGroupOfCart() error {
- res_ch := make(chan getGroupOfCartResult)
- req := getGroupOfCartRequest{}
- req.cart = ctx.Cart
- req.response = res_ch
- ctx.rddb.getGroupOfCartChan <- req
-
- res := <-res_ch
- if res.err != nil {
- return res.err
- }
- ctx.GroupName = res.group
- return nil
+func (ctx *ImportContext) getGroupOfCart() (err error) {
+ ctx.GroupName, err = ctx.rddb.GetGroupOfCart(ctx.Cart)
+ return
}
func (ctx *ImportContext) getShowInfo() (carts []uint, err error) {
- res_ch := make(chan getShowInfoResult)
- req := getShowInfoRequest{}
- req.showid = ctx.ShowId
- req.response = res_ch
- ctx.rddb.getShowInfoChan <- req
-
- res := <-res_ch
- if res.err != nil {
- err = res.err
- return
- }
- ctx.GroupName = res.group
- ctx.NormalizationLevel = res.norm_lvl
- ctx.AutotrimLevel = res.trim_lvl
+ ctx.GroupName, ctx.NormalizationLevel, ctx.AutotrimLevel, carts, err = ctx.rddb.GetShowInfo(ctx.ShowId)
ctx.Channels = 2
ctx.UseMetaData = true
- carts = res.carts
return
}
func (ctx *ImportContext) checkMusicGroup() (bool, error) {
- res_ch := make(chan checkMusicGroupResult)
- req := checkMusicGroupRequest{}
- req.group = ctx.GroupName
- req.response = res_ch
- ctx.rddb.checkMusicGroupChan <- req
-
- res := <-res_ch
- if res.err != nil {
- return false, res.err
- }
- return res.ismusic, nil
+ return ctx.rddb.CheckMusicGroup(ctx.GroupName)
}
func (ctx *ImportContext) getMusicInfo() (err error) {
- res_ch := make(chan getMusicInfoResult)
- req := getMusicInfoRequest{}
- req.group = ctx.GroupName
- req.response = res_ch
- ctx.rddb.getMusicInfoChan <- req
-
- res := <-res_ch
- if res.err != nil {
- return res.err
- }
- ctx.NormalizationLevel = res.norm_lvl
- ctx.AutotrimLevel = res.trim_lvl
+ ctx.NormalizationLevel, ctx.AutotrimLevel, err = ctx.rddb.GetMusicInfo(ctx.GroupName)
ctx.Channels = 2
ctx.UseMetaData = true
ctx.Cart = 0
diff --git a/rddb.go b/rddb.go
index 7466d9c..ead1ac0 100644
--- a/rddb.go
+++ b/rddb.go
@@ -177,7 +177,22 @@ func (self *RdDb) getPassword(username string, cached bool) (result getPasswordR
return
}
-func (self *RdDbChan) CheckPassword(username, password string) (result bool, err error) {
+func (self *RdDbChan) GetPassword(username string, cached bool) (string, error) {
+ res_ch := make(chan getPasswordResult)
+ req := getPasswordRequest{}
+ req.username = username
+ req.cached = cached
+ req.response = res_ch
+ self.getPasswordChan <- req
+
+ res := <-res_ch
+ if res.err != nil {
+ return "", res.err
+ }
+ return res.password, nil
+}
+
+func (self *RdDbChan) CheckPassword(username, password string) (bool, error) {
cached := true
for {
@@ -234,6 +249,20 @@ func (self *RdDb) getGroupOfCart(cart uint) (result getGroupOfCartResult) {
return
}
+func (self *RdDbChan) GetGroupOfCart(cart uint) (string, error) {
+ res_ch := make(chan getGroupOfCartResult)
+ req := getGroupOfCartRequest{}
+ req.cart = cart
+ req.response = res_ch
+ self.getGroupOfCartChan <- req
+
+ res := <-res_ch
+ if res.err != nil {
+ return "", res.err
+ }
+ return res.group, nil
+}
+
func (self *RdDb) getLogTableName(log string) (logtable string, err error) {
logtable = strings.Replace(log, " ", "_", -1) + "_LOG"
if !mysqlTableNameRe.MatchString(logtable) {
@@ -280,6 +309,20 @@ func (self *RdDb) getShowInfo(showid uint) (result getShowInfoResult) {
return
}
+func (self *RdDbChan) GetShowInfo(showid uint) (string, int, int, []uint, error) {
+ res_ch := make(chan getShowInfoResult)
+ req := getShowInfoRequest{}
+ req.showid = showid
+ req.response = res_ch
+ self.getShowInfoChan <- req
+
+ res := <-res_ch
+ if res.err != nil {
+ return "", 0, 0, nil, res.err
+ }
+ return res.group, res.norm_lvl, res.trim_lvl, res.carts, nil
+}
+
func (self *RdDb) checkMusicGroup(group string) (result checkMusicGroupResult) {
var cnt int
if result.err = self.checkMusicGroupStmt.QueryRow(group).Scan(&cnt); result.err != nil {
@@ -293,6 +336,20 @@ func (self *RdDb) checkMusicGroup(group string) (result checkMusicGroupResult) {
return
}
+func (self *RdDbChan) CheckMusicGroup(groupname string) (bool, error) {
+ res_ch := make(chan checkMusicGroupResult)
+ req := checkMusicGroupRequest{}
+ req.group = groupname
+ req.response = res_ch
+ self.checkMusicGroupChan <- req
+
+ res := <-res_ch
+ if res.err != nil {
+ return false, res.err
+ }
+ return res.ismusic, nil
+}
+
func (self *RdDb) getMusicInfo(group string) (result getMusicInfoResult) {
result.err = self.getMusicInfoStmt.QueryRow(group).Scan(&result.norm_lvl, &result.trim_lvl)
if result.err != nil {
@@ -304,6 +361,20 @@ func (self *RdDb) getMusicInfo(group string) (result getMusicInfoResult) {
return
}
+func (self *RdDbChan) GetMusicInfo(groupname string) (int, int, error) {
+ res_ch := make(chan getMusicInfoResult)
+ req := getMusicInfoRequest{}
+ req.group = groupname
+ req.response = res_ch
+ self.getMusicInfoChan <- req
+
+ res := <-res_ch
+ if res.err != nil {
+ return 0, 0, res.err
+ }
+ return res.norm_lvl, res.trim_lvl, nil
+}
+
func (self *RdDb) dispatchRequests() {
defer func() { self.done <- true }()
for {