Skip to content

fix: avoid infinite recusion due to cyclic dependency#373

Merged
appflowy merged 1 commit intomainfrom
filter-out-traversed-views
Mar 4, 2025
Merged

fix: avoid infinite recusion due to cyclic dependency#373
appflowy merged 1 commit intomainfrom
filter-out-traversed-views

Conversation

@khorshuheng
Copy link
Contributor

There are some edge cases where there is a cycle in a folder tree, which can lead to stack overflow. To break the cycle, we add an additional condition such that the traversal stops when a view id has been traversed before.

Copy link
Collaborator

@Horusiath Horusiath left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically we could change recursion to broad-/depth-first loop and be done with it, but it's ok. I only left little remark about unnecessary cloning.

txn: &T,
view_id: &str,
mut visited: HashSet<String>,
) -> Vec<View> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically since this method is recursive, it would be better to pass resulting &mut Vec<View> as accumulating argument instead of copying data over on each recursive step.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the method signature. Since there are significant number of changes now, i think it's better if i add some tests or test this end to end before merging.

Copy link
Collaborator

@Horusiath Horusiath Mar 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically you can still keep the public API unchanged, and move recursion and new params declaration to an inner (private) method. This should make it - more or less - a drop-in replacement.

@khorshuheng khorshuheng force-pushed the filter-out-traversed-views branch 2 times, most recently from 56ae552 to e265484 Compare March 3, 2025 15:16
@khorshuheng khorshuheng force-pushed the filter-out-traversed-views branch from e265484 to 295c7c6 Compare March 3, 2025 15:30
@appflowy appflowy merged commit 45239d2 into main Mar 4, 2025
6 checks passed
@appflowy appflowy deleted the filter-out-traversed-views branch March 4, 2025 06:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants