Skip to content

Commit

Permalink
merge from parent - remove accesor branches that did not change from …
Browse files Browse the repository at this point in the history
…parent branch
  • Loading branch information
tzahij committed Nov 9, 2020
1 parent 58eec37 commit 847cab4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
25 changes: 22 additions & 3 deletions catalog/db_diff_scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,31 @@ func (s *DiffScanner) diffFromParent(tx db.Tx, params doDiffParams) (*DiffScanne
After: params.After,
AdditionalFields: prepareDiffAdditionalFields(params.AdditionalFields),
}
s.leftScanner = NewDBLineageScanner(tx, params.LeftBranchID, CommittedID, scannerOpts)
s.rightScanner = NewDBLineageScanner(tx, params.RightBranchID, UncommittedID, scannerOpts)
s.childLineage, err = getLineage(tx, params.RightBranchID, UncommittedID)
parentLineage, err := getLineage(tx, params.LeftBranchID, CommittedID)
if err != nil {
return nil, err
}
childLineage, err := getLineage(tx, params.RightBranchID, UncommittedID)
if err != nil {
return nil, err
}
// If some ancestor branch commit id is the same for parent and child - then the parent does not need to read it
// so it is trimmed from the parent lineage
if len(parentLineage) >= 1 {
for i, _ := range parentLineage {
if parentLineage[i].CommitID == childLineage[i+1].CommitID {
parentLineage = parentLineage[:i]
break
}
}
}
parentOpts := scannerOpts
parentOpts.TrimmedLineage = parentLineage
childOpts := scannerOpts
childOpts.TrimmedLineage = childLineage
s.leftScanner = NewDBLineageScanner(tx, params.LeftBranchID, CommittedID, parentOpts)
s.rightScanner = NewDBLineageScanner(tx, params.RightBranchID, UncommittedID, childOpts)
s.childLineage = childLineage
return s, nil
}

Expand Down
8 changes: 7 additions & 1 deletion catalog/db_lineage_scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,16 @@ func (s *DBLineageScanner) ReadLineage() ([]lineageCommit, error) {
}

func (s *DBLineageScanner) ensureBranchScanners() bool {
var lineage []lineageCommit
var err error
if s.scanners != nil {
return true
}
lineage, err := s.ReadLineage()
if s.opts.TrimmedLineage != nil {
lineage = s.opts.TrimmedLineage
} else {
lineage, err = s.ReadLineage()
}
if err != nil {
s.err = fmt.Errorf("getting lineage: %w", err)
return false
Expand Down
1 change: 1 addition & 0 deletions catalog/db_scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type DBScannerOptions struct {
After string
AdditionalFields []string
AdditionalWhere sq.Sqlizer
TrimmedLineage []lineageCommit
}

type DBScanner interface {
Expand Down

0 comments on commit 847cab4

Please sign in to comment.