forked from treeverse/lakeFS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcataloger_list_branches.go
45 lines (39 loc) · 1.17 KB
/
cataloger_list_branches.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package catalog
import (
"context"
"github.com/treeverse/lakefs/db"
)
const ListBranchesMaxLimit = 10000
func (c *cataloger) ListBranches(ctx context.Context, repository string, prefix string, limit int, after string) ([]*Branch, bool, error) {
if err := Validate(ValidateFields{
{Name: "repository", IsValid: ValidateRepositoryName(repository)},
}); err != nil {
return nil, false, err
}
if limit < 0 || limit > ListBranchesMaxLimit {
limit = ListBranchesMaxLimit
}
prefixCond := db.Prefix(prefix)
res, err := c.db.Transact(func(tx db.Tx) (interface{}, error) {
repoID, err := c.getRepositoryIDCache(tx, repository)
if err != nil {
return nil, err
}
query := `SELECT $2 AS repository, name
FROM catalog_branches
WHERE repository_id = $1 AND name like $3 AND name > $4
ORDER BY name
LIMIT $5`
var branches []*Branch
if err := tx.Select(&branches, query, repoID, repository, prefixCond, after, limit+1); err != nil {
return nil, err
}
return branches, nil
}, c.txOpts(ctx, db.ReadOnly())...)
if err != nil {
return nil, false, err
}
branches := res.([]*Branch)
hasMore := paginateSlice(&branches, limit)
return branches, hasMore, nil
}