Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize UX for loading pipeline pages #1085

Merged
merged 6 commits into from
Apr 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ frontend/test/ui/visual-regression/screenshots/screen

# IDE
.idea/
.ijwb/
ml.iml

# Merge files
Expand Down
18 changes: 13 additions & 5 deletions backend/src/apiserver/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,27 @@ func NewOptions(listable Listable, pageSize int, sortBy string, filterProto *api
// Options o to the supplied SelectBuilder, and returns the new SelectBuilder
// containing these.
func (o *Options) AddPaginationToSelect(sqlBuilder sq.SelectBuilder) sq.SelectBuilder {
sqlBuilder = o.AddSortingToSelect(sqlBuilder)
// Add one more item than what is requested.
sqlBuilder = sqlBuilder.Limit(uint64(o.PageSize + 1))

return sqlBuilder
}

// AddPaginationToSelect adds WHERE clauses with the sorting and pagination criteria in the
// Options o to the supplied SelectBuilder, and returns the new SelectBuilder
// containing these.
func (o *Options) AddSortingToSelect(sqlBuilder sq.SelectBuilder) sq.SelectBuilder {
// If next row's value is specified, set those values in the clause.
if o.SortByFieldValue != nil && o.KeyFieldValue != nil {
if o.IsDesc {
sqlBuilder = sqlBuilder.
Where(sq.Or{sq.Lt{o.SortByFieldName: o.SortByFieldValue},
sq.And{sq.Eq{o.SortByFieldName: o.SortByFieldValue}, sq.LtOrEq{o.KeyFieldName: o.KeyFieldValue}}})
sq.And{sq.Eq{o.SortByFieldName: o.SortByFieldValue}, sq.LtOrEq{o.KeyFieldName: o.KeyFieldValue}}})
} else {
sqlBuilder = sqlBuilder.
Where(sq.Or{sq.Gt{o.SortByFieldName: o.SortByFieldValue},
sq.And{sq.Eq{o.SortByFieldName: o.SortByFieldValue}, sq.GtOrEq{o.KeyFieldName: o.KeyFieldValue}}})
sq.And{sq.Eq{o.SortByFieldName: o.SortByFieldValue}, sq.GtOrEq{o.KeyFieldName: o.KeyFieldValue}}})
}
}

Expand All @@ -185,9 +196,6 @@ func (o *Options) AddPaginationToSelect(sqlBuilder sq.SelectBuilder) sq.SelectBu
OrderBy(fmt.Sprintf("%v %v", o.SortByFieldName, order)).
OrderBy(fmt.Sprintf("%v %v", o.KeyFieldName, order))

// Add one more item than what is requested.
sqlBuilder = sqlBuilder.Limit(uint64(o.PageSize + 1))

return sqlBuilder
}

Expand Down
6 changes: 2 additions & 4 deletions backend/src/apiserver/storage/job_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,13 @@ func (s *JobStore) buildSelectJobsQuery(selectCount bool, opts *list.Options,
}

sqlBuilder := opts.AddFilterToSelect(filteredSelectBuilder)
if err != nil {
return "", nil, util.NewInternalServerError(err, "Failed to list jobs: %v", err)
}

// If we're not just counting, then also add select columns and perform a left join
// to get resource reference information. Also add pagination.
if !selectCount {
sqlBuilder = opts.AddPaginationToSelect(filteredSelectBuilder)
sqlBuilder = s.addResourceReferences(sqlBuilder)
sqlBuilder = opts.AddPaginationToSelect(sqlBuilder)
sqlBuilder = opts.AddSortingToSelect(sqlBuilder)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wonder if it's still required to add sorting query if inner result has already been sorted.

}
sql, args, err := sqlBuilder.ToSql()
if err != nil {
Expand Down
7 changes: 2 additions & 5 deletions backend/src/apiserver/storage/run_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,21 +145,18 @@ func (s *RunStore) buildSelectRunsQuery(selectCount bool, opts *list.Options,
}

sqlBuilder := opts.AddFilterToSelect(filteredSelectBuilder)
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this removed?

return "", nil, util.NewInternalServerError(err, "Failed to list runs: %v", err)
}

// If we're not just counting, then also add select columns and perform a left join
// to get resource reference information. Also add pagination.
if !selectCount {
sqlBuilder = opts.AddPaginationToSelect(filteredSelectBuilder)
sqlBuilder = s.addMetricsAndResourceReferences(sqlBuilder)
sqlBuilder = opts.AddPaginationToSelect(sqlBuilder)
sqlBuilder = opts.AddSortingToSelect(sqlBuilder)
}
sql, args, err := sqlBuilder.ToSql()
if err != nil {
return "", nil, util.NewInternalServerError(err, "Failed to list runs: %v", err)
}

return sql, args, err
}

Expand Down