mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-01-18 06:30:07 +08:00
simplify if else logic
This commit is contained in:
parent
f0c89cfacd
commit
8a1c8e41b3
@ -145,46 +145,49 @@ func (fsw *FilerStoreWrapper) ListDirectoryPrefixedEntries(ctx context.Context,
|
|||||||
}()
|
}()
|
||||||
entries, err := fsw.ActualStore.ListDirectoryPrefixedEntries(ctx, dirPath, startFileName, includeStartFile, limit, prefix)
|
entries, err := fsw.ActualStore.ListDirectoryPrefixedEntries(ctx, dirPath, startFileName, includeStartFile, limit, prefix)
|
||||||
if err == ErrUnsupportedListDirectoryPrefixed {
|
if err == ErrUnsupportedListDirectoryPrefixed {
|
||||||
count := 0
|
entries, err = fsw.prefixFilterEntries(ctx, dirPath, startFileName, includeStartFile, limit, prefix)
|
||||||
notPrefixed, err := fsw.ActualStore.ListDirectoryEntries(ctx, dirPath, startFileName, includeStartFile, limit)
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if prefix == "" {
|
|
||||||
entries = notPrefixed
|
|
||||||
} else {
|
|
||||||
var lastFileName string
|
|
||||||
for count < limit {
|
|
||||||
for _, entry := range notPrefixed {
|
|
||||||
lastFileName = entry.Name()
|
|
||||||
if strings.HasPrefix(entry.Name(), prefix) {
|
|
||||||
count++
|
|
||||||
entries = append(entries, entry)
|
|
||||||
}
|
|
||||||
if count >= limit {
|
|
||||||
goto Exit
|
|
||||||
}
|
|
||||||
}
|
|
||||||
notPrefixed, err = fsw.ActualStore.ListDirectoryEntries(ctx, dirPath, lastFileName, false, limit)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(notPrefixed) == 0 {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Exit:
|
|
||||||
}
|
|
||||||
} else if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
for _, entry := range entries {
|
for _, entry := range entries {
|
||||||
filer_pb.AfterEntryDeserialization(entry.Chunks)
|
filer_pb.AfterEntryDeserialization(entry.Chunks)
|
||||||
}
|
}
|
||||||
return entries, nil
|
return entries, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (fsw *FilerStoreWrapper) prefixFilterEntries(ctx context.Context, dirPath util.FullPath, startFileName string, includeStartFile bool, limit int, prefix string) (entries []*Entry, err error) {
|
||||||
|
entries, err = fsw.ActualStore.ListDirectoryEntries(ctx, dirPath, startFileName, includeStartFile, limit)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if prefix == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
count := 0
|
||||||
|
var lastFileName string
|
||||||
|
notPrefixed := entries
|
||||||
|
entries = nil
|
||||||
|
for count < limit && len(notPrefixed) > 0 {
|
||||||
|
for _, entry := range notPrefixed {
|
||||||
|
lastFileName = entry.Name()
|
||||||
|
if strings.HasPrefix(entry.Name(), prefix) {
|
||||||
|
count++
|
||||||
|
entries = append(entries, entry)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if count < limit {
|
||||||
|
notPrefixed, err = fsw.ActualStore.ListDirectoryEntries(ctx, dirPath, lastFileName, false, limit-count)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func (fsw *FilerStoreWrapper) BeginTransaction(ctx context.Context) (context.Context, error) {
|
func (fsw *FilerStoreWrapper) BeginTransaction(ctx context.Context) (context.Context, error) {
|
||||||
return fsw.ActualStore.BeginTransaction(ctx)
|
return fsw.ActualStore.BeginTransaction(ctx)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user