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

api: improve search performance on the DAG List page #757

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
28 changes: 19 additions & 9 deletions internal/persistence/local/dag_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,11 @@ func (d *dagStoreImpl) ensureDirExist() error {
return nil
}

func (d *dagStoreImpl) searchName(fileName string, searchText *string) bool {
if searchText == nil {
func (d *dagStoreImpl) containsSearchText(text string, search *string) bool {
if search == nil {
return true
}
fileName = strings.TrimSuffix(fileName, path.Ext(fileName))
ret := strings.Contains(strings.ToLower(fileName), strings.ToLower(*searchText))
ret := strings.Contains(strings.ToLower(text), strings.ToLower(*search))
return ret
}

Expand Down Expand Up @@ -191,20 +190,31 @@ func (d *dagStoreImpl) ListPagination(ctx context.Context, params persistence.DA
currentDag *digraph.DAG
)

if err := filepath.WalkDir(d.dir, func(_ string, dir fs.DirEntry, err error) error {
if err := filepath.WalkDir(d.dir, func(_ string, entry fs.DirEntry, err error) error {
if err != nil {
return err
}

if dir.IsDir() || !checkExtension(dir.Name()) {
if entry.IsDir() || !checkExtension(entry.Name()) {
return nil
}

if currentDag, err = d.GetMetadata(ctx, dir.Name()); err != nil {
errList = append(errList, fmt.Sprintf("reading %s failed: %s", dir.Name(), err))
baseName := path.Base(entry.Name())
dagName := strings.TrimSuffix(baseName, path.Ext(baseName))
if params.Tag == nil || *params.Tag == "" {
// if tag is not provided, check before reading the file
if !d.containsSearchText(dagName, params.Name) {
// skip the file if the name
return nil
}
}

// if tag is provided, read the file and check the tag
if currentDag, err = d.GetMetadata(ctx, dagName); err != nil {
errList = append(errList, fmt.Sprintf("reading %s failed: %s", dagName, err))
}

if !d.searchName(dir.Name(), params.Name) || currentDag == nil || !d.searchTags(currentDag.Tags, params.Tag) {
if !d.containsSearchText(dagName, params.Name) || currentDag == nil || !d.searchTags(currentDag.Tags, params.Tag) {
return nil
}

Expand Down
Loading