Explorar o código

Merge pull request #13 from AI-ASS/main

fix the issue of model repetition
Calcium-Ion %!s(int64=2) %!d(string=hai) anos
pai
achega
d4b3f87368
Modificáronse 1 ficheiros con 4 adicións e 8 borrados
  1. 4 8
      model/ability.go

+ 4 - 8
model/ability.go

@@ -14,14 +14,10 @@ type Ability struct {
 }
 
 func GetGroupModels(group string) []string {
-	var abilities []Ability
-	//去重 enabled = true
-	DB.Where("`group` = ? and enabled = ?", group, true).Find(&abilities)
-	models := make([]string, 0, len(abilities))
-	for _, ability := range abilities {
-		models = append(models, ability.Model)
-	}
-	return models
+    var models []string
+    // Find distinct models
+    DB.Table("abilities").Where("`group` = ? and enabled = ?", group, true).Distinct("model").Pluck("model", &models)
+    return models
 }
 
 func GetRandomSatisfiedChannel(group string, model string) (*Channel, error) {