Skip to content

Commit

Permalink
optimise sql
Browse files Browse the repository at this point in the history
Signed-off-by: jiefenghuang <[email protected]>
  • Loading branch information
jiefenghuang committed Sep 27, 2024
1 parent b0e21d1 commit 394b796
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions pkg/meta/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -4486,19 +4486,25 @@ func (m *dbMeta) getDirFetcher() dirFetcher {
return func(ctx Context, inode Ino, cursor interface{}, offset, limit int, plus bool) (interface{}, []*Entry, error) {
var entries []*Entry
err := m.roTxn(func(s *xorm.Session) error {
s = s.Table(&edge{})
if plus {
s = s.Join("INNER", &node{}, "jfs_edge.inode=jfs_node.inode")
}
iCursor := offset
if cursor != nil {
iCursor = cursor.(int)
}
s = s.Limit(limit, iCursor).OrderBy("jfs_edge.inode")

var ids []int64
if err := s.Table(&edge{}).Cols("id").Where("parent = ?", inode).Limit(limit, iCursor).Find(&ids); err != nil {
return err
}

s = s.Table(&edge{}).Cols("jfs_edge.inode", "jfs_edge.name", "jfs_edge.type").In("jfs_edge.id", ids)
if true {
s = s.Join("INNER", &node{}, "jfs_edge.inode=jfs_node.inode")
}
var nodes []namedNode
if err := s.Find(&nodes, &edge{Parent: inode}); err != nil {
if err := s.Find(&nodes); err != nil {
return err
}

for _, n := range nodes {
if len(n.Name) == 0 {
logger.Errorf("Corrupt entry with empty name: inode %d parent %d", n.Inode, inode)
Expand Down

0 comments on commit 394b796

Please sign in to comment.