Skip to content

Commit

Permalink
improve 321 ua performance (#3957)
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Zhao <[email protected]>
  • Loading branch information
PetrusZ authored Jan 10, 2025
1 parent 8c7f258 commit a7ef527
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
11 changes: 8 additions & 3 deletions pkg/cli/upgradeassistant/cmd/migrate/321.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
package migrate

import (
"context"
"fmt"
"time"

"github.com/koderover/zadig/v2/pkg/cli/upgradeassistant/internal/upgradepath"
"github.com/koderover/zadig/v2/pkg/microservice/aslan/config"
"github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/repository/models"
commonmodels "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/repository/models"
commonrepo "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/repository/mongodb"
"github.com/koderover/zadig/v2/pkg/shared/handler"
Expand Down Expand Up @@ -61,13 +63,16 @@ func migrateReleasePlanCron(ctx *handler.Context) error {
return fmt.Errorf("failed to delete release plan cronjobs, error: %w", err)
}

releasePlans, _, err := commonrepo.NewReleasePlanColl().ListByOptions(&commonrepo.ListReleasePlanOption{})
cursor, err := commonrepo.NewReleasePlanColl().ListByCursor()
if err != nil {
return fmt.Errorf("failed to list release plans, error: %w", err)
}
for cursor.Next(context.Background()) {
var releasePlan models.ReleasePlan
if err := cursor.Decode(&releasePlan); err != nil {
return err
}

// create new cronjob for release plan if schedule time is after now and status is executing
for _, releasePlan := range releasePlans {
if releasePlan.ScheduleExecuteTime != 0 && releasePlan.Status == config.StatusExecuting {
if time.Unix(releasePlan.ScheduleExecuteTime, 0).After(time.Now()) {
releasePlanCronName := util.GetReleasePlanCronName(releasePlan.ID.Hex(), releasePlan.Name, releasePlan.Index)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,8 @@ func (c *ReleasePlanColl) ListFinishedReleasePlan(startTime, endTime int64) ([]*

return resp, nil
}

func (c *ReleasePlanColl) ListByCursor() (*mongo.Cursor, error) {
query := bson.M{}
return c.Collection.Find(context.TODO(), query)
}

0 comments on commit a7ef527

Please sign in to comment.