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

meta/sql: fix readdir query #5482

Merged
merged 1 commit into from
Dec 30, 2024
Merged
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
7 changes: 3 additions & 4 deletions pkg/meta/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,6 @@ func newSQLMeta(driver, addr string, conf *Config) (Meta, error) {
default:
engine.SetLogLevel(log.LOG_OFF)
}

start := time.Now()
if err = engine.Ping(); err != nil {
return nil, fmt.Errorf("ping database: %s", err)
Expand Down Expand Up @@ -4601,7 +4600,7 @@ func (m *dbMeta) getDirFetcher() dirFetcher {
} else {
if offset > 0 {
var edges []edge
if err := s.Table(&edge{}).Where("parent = ?", inode).Limit(1, offset-1).Find(&edges); err != nil {
if err := s.Table(&edge{}).Where("parent = ?", inode).OrderBy("name").Limit(1, offset-1).Find(&edges); err != nil {
return err
}
if len(edges) < 1 {
Expand All @@ -4615,9 +4614,9 @@ func (m *dbMeta) getDirFetcher() dirFetcher {
var err error
// sorted by (parent, name) index
if name == nil {
err = s.Table(&edge{}).Cols("id").Where("parent = ?", inode).Limit(limit).Find(&ids)
err = s.Table(&edge{}).Cols("id").Where("parent = ?", inode).OrderBy("name").Limit(limit).Find(&ids)
} else {
err = s.Table(&edge{}).Cols("id").Where("parent = ? and name > ?", inode, name).Limit(limit).Find(&ids)
err = s.Table(&edge{}).Cols("id").Where("parent = ? and name > ?", inode, name).OrderBy("name").Limit(limit).Find(&ids)
}
if err != nil {
return err
Expand Down
Loading