From a7ef527b512678d91341c04ff0dd4e9d2c5e7df0 Mon Sep 17 00:00:00 2001 From: Petrus Date: Fri, 10 Jan 2025 15:21:58 +0800 Subject: [PATCH] improve 321 ua performance (#3957) Signed-off-by: Patrick Zhao --- pkg/cli/upgradeassistant/cmd/migrate/321.go | 11 ++++++++--- .../core/common/repository/mongodb/release_plan.go | 5 +++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/pkg/cli/upgradeassistant/cmd/migrate/321.go b/pkg/cli/upgradeassistant/cmd/migrate/321.go index 845c919f24..c711961e97 100644 --- a/pkg/cli/upgradeassistant/cmd/migrate/321.go +++ b/pkg/cli/upgradeassistant/cmd/migrate/321.go @@ -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" @@ -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) diff --git a/pkg/microservice/aslan/core/common/repository/mongodb/release_plan.go b/pkg/microservice/aslan/core/common/repository/mongodb/release_plan.go index beff221f23..52e161eed6 100644 --- a/pkg/microservice/aslan/core/common/repository/mongodb/release_plan.go +++ b/pkg/microservice/aslan/core/common/repository/mongodb/release_plan.go @@ -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) +}