修改节点分配方式
This commit is contained in:
@@ -37,16 +37,18 @@ func FindCitiesWithEdgesCount(tx *gorm.DB) ([]model.City, error) {
|
||||
return cities, nil
|
||||
}
|
||||
|
||||
func UpdateCityOffset(tx *gorm.DB, city int, offset int) error {
|
||||
if offset < 0 {
|
||||
return fmt.Errorf("offset must be non-negative")
|
||||
func UpdateCitiesOffset(tx *gorm.DB, updates []model.City) error {
|
||||
if len(updates) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
err := tx.Model(&model.City{}).
|
||||
Where("id = ?", city).
|
||||
Update("offset", offset).Error
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to update cities offset: %w", err)
|
||||
for _, city := range updates {
|
||||
err := tx.Model(new(model.City)).
|
||||
Where("id = ?", city.Id).
|
||||
Update("offset", city.Offset).Error
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to update city id %d offset: %w", city.Id, err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user