diff --git a/database/gdb/gdb.go b/database/gdb/gdb.go index b7af2116cb..74d76e5c8a 100644 --- a/database/gdb/gdb.go +++ b/database/gdb/gdb.go @@ -701,13 +701,13 @@ func getConfigNodeByWeight(cg ConfigGroup) *ConfigNode { } // Exclude the right border value. var ( - min = 0 - max = 0 - random = grand.N(0, total-1) + minWeight = 0 + maxWeight = 0 + random = grand.N(0, total-1) ) for i := 0; i < len(cg); i++ { - max = min + cg[i].Weight*100 - if random >= min && random < max { + maxWeight = minWeight + cg[i].Weight*100 + if random >= minWeight && random < maxWeight { // ==================================================== // Return a COPY of the ConfigNode. // ==================================================== @@ -715,7 +715,7 @@ func getConfigNodeByWeight(cg ConfigGroup) *ConfigNode { node = cg[i] return &node } - min = max + minWeight = maxWeight } return nil } diff --git a/database/gdb/gdb_model_hook.go b/database/gdb/gdb_model_hook.go index 7dd0074057..3428990a73 100644 --- a/database/gdb/gdb_model_hook.go +++ b/database/gdb/gdb_model_hook.go @@ -66,11 +66,12 @@ type internalParamHookDelete struct { // which is usually not be interesting for upper business hook handler. type HookSelectInput struct { internalParamHookSelect - Model *Model // Current operation Model. - Table string // The table name that to be used. Update this attribute to change target table name. - Schema string // The schema name that to be used. Update this attribute to change target schema name. - Sql string // The sql string that to be committed. - Args []interface{} // The arguments of sql. + Model *Model // Current operation Model. + Table string // The table name that to be used. Update this attribute to change target table name. + Schema string // The schema name that to be used. Update this attribute to change target schema name. + Sql string // The sql string that to be committed. + Args []interface{} // The arguments of sql. + SelectType SelectType // The type of this SELECT operation. } // HookInsertInput holds the parameters for insert hook operation. diff --git a/database/gdb/gdb_model_select.go b/database/gdb/gdb_model_select.go index 5c30cdee2d..8c6433abf0 100644 --- a/database/gdb/gdb_model_select.go +++ b/database/gdb/gdb_model_select.go @@ -682,10 +682,11 @@ func (m *Model) doGetAllBySql( }, handler: m.hookHandler.Select, }, - Model: m, - Table: m.tables, - Sql: sql, - Args: m.mergeArguments(args), + Model: m, + Table: m.tables, + Sql: sql, + Args: m.mergeArguments(args), + SelectType: selectType, } if result, err = in.Next(ctx); err != nil { return