Skip to content

Commit

Permalink
fix(fetch): fix wrong use of db.Fetch (#6669)
Browse files Browse the repository at this point in the history
  • Loading branch information
d4x1 authored Dec 19, 2023
1 parent f1ddaa9 commit 79e1f91
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ type removeCreatedDateAfterFromCollectorMeta20230223 struct{}
func (script *removeCreatedDateAfterFromCollectorMeta20230223) Up(basicRes context.BasicRes) errors.Error {
db := basicRes.GetDal()
// step 1: rename bp.settings.createdDateAfter to timeAfter
bp := &blueprint20230223{}
cursor, err := db.Cursor(dal.From(bp), dal.Where("mode = ?", "NORMAL"))
cursor, err := db.Cursor(dal.From(&blueprint20230223{}), dal.Where("mode = ?", "NORMAL"))
if err != nil {
return err
}
defer cursor.Close()
for cursor.Next() {
bp := &blueprint20230223{}
err = db.Fetch(cursor, bp)
if err != nil {
return err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ func (script *normalizeBpSettings) Up(basicRes context.BasicRes) errors.Error {
return errors.BadInput.New("invalid encKey")
}
db := basicRes.GetDal()
bp := &blueprint20230829{}
cursor := errors.Must1(db.Cursor(dal.From(bp)))
cursor := errors.Must1(db.Cursor(dal.From(&blueprint20230829{})))
defer cursor.Close()

for cursor.Next() {
// load row
bp := &blueprint20230829{}
errors.Must(db.Fetch(cursor, bp))
// decrypt and unmarshal settings
settingsJson := errors.Must1(plugin.Decrypt(encKey, bp.Settings))
Expand Down
2 changes: 1 addition & 1 deletion backend/helpers/migrationhelper/migrationhelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ func TransformColumns[S any, D any](
return errors.Default.Wrap(err, fmt.Sprintf("failed to instantiate BatchSave for table [%s]", tableName))
}
defer batch.Close()
src := new(S)
for cursor.Next() {
src := new(S)
err = db.Fetch(cursor, src)
if err != nil {
return errors.Default.Wrap(err, fmt.Sprintf("fail to load record from table [%s]", tableName))
Expand Down
3 changes: 1 addition & 2 deletions backend/helpers/pluginhelper/api/api_extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ func (extractor *ApiExtractor) Execute() errors.Error {
}
logger.Info("get data from %s where params=%s and got %d", extractor.table, extractor.params, count)
defer cursor.Close()
row := &RawData{}

// batch save divider
divider := NewBatchSaveDivider(extractor.args.Ctx, extractor.args.BatchSize, extractor.table, extractor.params)

Expand All @@ -108,6 +106,7 @@ func (extractor *ApiExtractor) Execute() errors.Error {
return errors.Convert(ctx.Err())
default:
}
row := &RawData{}
err = db.Fetch(cursor, row)
if err != nil {
return errors.Default.Wrap(err, "error fetching row")
Expand Down
4 changes: 2 additions & 2 deletions backend/helpers/pluginhelper/api/graphql_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,8 @@ func (collector *GraphqlCollector) ExtractExistRawData(divider *BatchSaveDivider
}
logger.Info("get data from %s where params=%s and got %d", collector.table, collector.params, count)
defer cursor.Close()
row := &RawData{}

// prgress
// progress
collector.args.Ctx.SetProgress(0, -1)
ctx := collector.args.Ctx.GetContext()
// iterate all rows
Expand All @@ -323,6 +322,7 @@ func (collector *GraphqlCollector) ExtractExistRawData(divider *BatchSaveDivider
}
// get the type of query and variables. For each iteration, the query should be a different object
query, variables, _ := collector.args.BuildQuery(nil)
row := &RawData{}
err = db.Fetch(cursor, row)
if err != nil {
return errors.Default.Wrap(err, "error fetching row")
Expand Down
7 changes: 2 additions & 5 deletions backend/plugins/ae/tasks/commits_convertor.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,9 @@ import (
func ConvertCommits(taskCtx plugin.SubTaskContext) errors.Error {
db := taskCtx.GetDal()
data := taskCtx.GetData().(*AeTaskData)

aeCommit := &aeModels.AECommit{}

// Get all the commits from the domain layer
cursor, err := db.Cursor(
dal.From(aeCommit),
dal.From(&aeModels.AECommit{}),
dal.Where("ae_project_id = ?", data.Options.ProjectId),
)
if err != nil {
Expand All @@ -53,7 +50,7 @@ func ConvertCommits(taskCtx plugin.SubTaskContext) errors.Error {
}
// uncomment following line if you want to test out canceling feature for this task
//time.Sleep(1 * time.Second)

aeCommit := &aeModels.AECommit{}
err = db.Fetch(cursor, aeCommit)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion backend/plugins/refdiff/tasks/commit_diff_calculator.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ func CalculateCommitsDiff(taskCtx plugin.SubTaskContext) errors.Error {
insertCountLimitOfCommitsDiff := int(65535 / reflect.ValueOf(code.CommitsDiff{}).NumField())

// load commits from db
commitParent := &code.CommitParent{}
cursor, err := db.Cursor(
dal.Select("cp.*"),
dal.Join("LEFT JOIN repo_commits rc ON (rc.commit_sha = cp.commit_sha)"),
Expand All @@ -94,6 +93,7 @@ func CalculateCommitsDiff(taskCtx plugin.SubTaskContext) errors.Error {
return errors.Convert(ctx.Err())
default:
}
commitParent := &code.CommitParent{}
err = db.Fetch(cursor, commitParent)
if err != nil {
return errors.Default.Wrap(err, "failed to read commit from database")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,13 @@ func loadCommitGraph(ctx context.Context, db dal.Dal, data *RefdiffTaskData) (*u
}
defer cursor.Close()

commitParent := &code.CommitParent{}
for cursor.Next() {
select {
case <-ctx.Done():
return nil, errors.Convert(ctx.Err())
default:
}
commitParent := &code.CommitParent{}
err = db.Fetch(cursor, commitParent)
if err != nil {
return nil, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ func CalculatePrCherryPick(taskCtx plugin.SubTaskContext) errors.Error {

defer cursor.Close()

pr := &code.PullRequest{}
var parentPrKeyInt int
taskCtx.SetProgress(0, -1)

Expand All @@ -79,7 +78,7 @@ func CalculatePrCherryPick(taskCtx plugin.SubTaskContext) errors.Error {
return errors.Convert(ctx.Err())
default:
}

pr := &code.PullRequest{}
err = db.Fetch(cursor, pr)
if err != nil {
return errors.Convert(err)
Expand Down
4 changes: 2 additions & 2 deletions backend/server/services/pipeline_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,8 @@ func ComputePipelineStatus(pipeline *models.Pipeline, isCancelled bool) (string,

// GetLatestTasksOfPipeline returns latest tasks (reran tasks are excluding) of specified pipeline
func GetLatestTasksOfPipeline(pipeline *models.Pipeline) ([]*models.Task, errors.Error) {
task := &models.Task{}
cursor, err := db.Cursor(
dal.From(task),
dal.From(&models.Task{}),
dal.Where("pipeline_id = ?", pipeline.ID),
dal.Orderby("id DESC"), // sort it by id so we can hit the latest task first for the RERUNed row/col
)
Expand All @@ -160,6 +159,7 @@ func GetLatestTasksOfPipeline(pipeline *models.Pipeline) ([]*models.Task, errors
type rowcol struct{ row, col int }
memorized := make(map[rowcol]bool)
for cursor.Next() {
task := &models.Task{}
if e := db.Fetch(cursor, task); e != nil {
return nil, errors.Convert(e)
}
Expand Down

0 comments on commit 79e1f91

Please sign in to comment.