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

generalize the tree macro to support any field #8134

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

andjar
Copy link
Contributor

@andjar andjar commented Apr 5, 2024

The tree macro is modified to support a field parameter, defaulting to title for backward compatibility. As suggested in #8129, a tiddler with fields

title: /A/B/C
path1: /B/A/C
path2: /C/B/A

will be placed at different locations in the tree using the calls

<<tree prefix:"/">> // Defaults to title
<<tree prefix:"/" field:"path1">>
<<tree prefix:"/" field:"path2">>

The performance seems suboptimal compared to the original implementation, possibly due to nested looping over all tiddlers in tree_node:

<$list filter="[all[shadows+tiddlers]get<__field__>prefix<__prefix__>removeprefix<__prefix__>splitbefore<__separator__>sort[]!suffix<__separator__>]" variable="chunk">
<$list filter="[all[shadows+tiddlers]has<__field__>sort[]] :filter[get<__field__>removeprefix<__prefix__>match<chunk>]" variable="title">
<$macrocall $name="leaf-node" prefix=<<__prefix__>> chunk=<<chunk>> title=<<title>> separator=<<__separator__>>/>
</$list>
</$list>

Make the tree macro accepts custom fields
Copy link

vercel bot commented Apr 5, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
tiddlywiki5 ✅ Ready (Inspect) Visit Preview Apr 17, 2024 8:33pm

core/wiki/macros/tree.tid Outdated Show resolved Hide resolved
<$list filter="[all[shadows+tiddlers]get<__field__>prefix<__prefix__>removeprefix<__prefix__>splitbefore<__separator__>sort[]!suffix<__separator__>]" variable="chunk">
<$list filter="[all[shadows+tiddlers]has<__field__>sort[]] :filter[get<__field__>removeprefix<__prefix__>match<chunk>]" variable="title">
<$macrocall $name="leaf-node" prefix=<<__prefix__>> chunk=<<chunk>> title=<<title>> separator=<<__separator__>>/>
</$list>
Copy link
Contributor

@pmario pmario Apr 6, 2024

Choose a reason for hiding this comment

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

Having 2 lists that iterate over every shadow and every tiddler starting from new, may be the performance bottle neck - as you suggest. So if possible we may be able to "reuse" some results from the first list as input to the second one. -- But I did not have a look at the code at the moment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree that the performance must be improved. The challenge, I think, is that we need to (1) find and sort the list of all valid field values (i.e., those with a given prefix) and (2) find all tiddlers with the given field values

One strategy may be to

  1. Find tiddlers with valid field values
  2. Join field value and tiddler title with the separator
  3. Sort the list of field value-tiddler title strings
  4. Split by the separator and somehow extract the last element (tiddler title)

But that would require a larger re-write of the tree macro

improve backwards compatibility
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.

None yet

2 participants