A Modified Recent Tab (History Tab)

This is a sidebar History Tab, accepts a filter and displays tiddlers meets that criteria on a monthly basis for selected year. Like April 2014

\define each-month()
<div class="tc-menu-list-item">
<$text text={{{ [[$(year-month)$15]format:date[MMM YYYY]] }}}/>
</div>
<$list filter="[subfilter<__filter__>] :filter[get[modified]prefix[$(year-month)$]] :sort:date[get[modified]else[20000101120000000]]">
<!-- Same Month -->
<div class="tc-menu-list-subitem">
<$link/><!-- - <$view field=modified format=date template="YYYY-0MM-0DD 0hh:0mm:0ss"/> -->
</div>
</$list>
\end

\define recent-monthly(filter, year:"")
<$list filter="[subfilter<__filter__>get[modified]prefix<__year__>format:date[YYYY0MM]unique[]!sort[]]" variable="year-month">
   <<each-month>>
</$list>
\end

<!-- implement the UI -->
\define setFilterAction()
<$action-setfield    $tiddler=<<stateTid>> $field="filter" $value={{{[<stateTid>get[text]]}}} />
<$action-setfield    $tiddler=<<stateTid>> $field="year"   $value="" />
\end

\define select-year()
<$select tiddler=<<stateTid>> field=year default="" >
<option value="">All years</option>
<$list filter=<<yearFilter>> >
<option><$text text=<<currentTiddler>>/></option>
</$list>
</$select>
\end

<$let 
   stateTid=      "$:/state/recent-monthly"
   defaultFilter= "[!is[system]]"
   mainFilter=    {{{ [<stateTid>get[filter]else<defaultFilter>] }}}
	 yearFilter=    "[subfilter<mainFilter>get[modified]format:date[YYYY]unique[]!sort[]]"
	 year=          {{{ [<stateTid>get[year]] }}}
   currentTiddler=<<currentTab>> ><!-- this last variable is used to let macro works in sidebar tab -->

<$keyboard key="enter" actions=<<setFilterAction>> >
  <$edit-text tiddler=<<stateTid>> default=<<defaultFilter>> placeholder="enter a valid filter like [tag[HelloThere]]" tag=input class="w-50" focus=yes type=search/>
</$keyboard>
<<select-year>>
<$list filter="[<stateTid>get[text]!match<mainFilter>] +[limit[1]]" variable=null>
  <$button actions=<<setFilterAction>> >Set filter</$button>
</$list>

<!--results -->
<div class="tc-search-results">
<small>Total results for <code><$text text=<<mainFilter>> /></code>: <$count filter=<<mainFilter>> /> matches</small>
<$macrocall $name="recent-monthly" year=<<year>> filter=<<mainFilter>> />
</div>

</$let>

Screencast

dvQGzoKCt7

To give a try

  1. download History.json (2.4 KB)

  2. drag and drop to https://tiddlywiki.com

  3. From sidebar, open the History tab

  4. Type your filter and press enter

  5. Select the year

Important: You need to press enter after typing the filter! This is only for the sake of better performance.

Credits

  1. TW_Tones
  2. Eric Shulman

EDIT Code updated on 2022.08.27

1 Like

When you use [all[tiddlers+shadows]] (means all tiddlers in wiki) the code makes TW slow. You may have suggestion to improve the performance by using simpler code, and better algorithm. Here the filter is calculated in several parts! I used the $set to calculate the filter once, but it does not make a big difference with respect the current code.

Important Notes
1: The performance on official Tiddlywiki with around 4000 tiddlers is fantastic.
2. On a Tiddlywiki with ~36000 tiddler you will see the slowness of TW with [all[tiddlers+shadows]]

So on medium size Tiddlywiki it works fine.

Question: I have not a TW with that amount of tiddlers, is there any way to create a sandbox to check the performance?

Yes: Use Tiddler Commander plugin, It can create bulk of tiddlers, it allows you to change the created/modified dates

Can you post a demo that shows the performance issues? At a very quick glance I see some redundant sorting happening, and some sorting that would be better done after you have just the number of years left rather than sorting all tiddlers upfront.

Hi Saq,
I did not measure the performance. It just takes time on big TW, you observe some lags.

  1. when you set the filter (first time results are calculated)
  2. when you change the year for those years with a lot of results

Edit: On official TW with 4000 tiddlers the speed is reasonable, no lag is seen.

Mohammad thanks for sharing this, I can see it being of great use especially on long running personal wikis. I particularly like the application of the subfilter. As we become advanced filter users sometimes it is just as easy to enter a filter to get exactly what we want.

A Possible future inclusion:
Advanced Search > Filter > Dropdown Allows you to select from tiddlers tagged $:/tags/Filter containing a description and filter field.

Perhaps this drop down could be used to set the filter in the history sidebar.

  • I think we could make a few UI items to allow selection of filters from such filter tiddlers, and creating a new filter tiddler from a filter.

How hard would it be to add an all years option?

It is easy! removing the year prefix allows to list all years.

Yes, I like the idea! Filter in Advanced Search can do the job with suitable filters.

1 Like

But can it be a selectable option in your solution?

I will update the code shortly!

The only issue is when all years is set by default the TW gets slow!

Yes, but then the filter makes all the difference. If the “sub filter” constrains the output then performance should be fine.

  • Its fine to include a warning notification, even a confirm widget before setting this to all.
  • If the tab is not active or sidebar shut this will not be refreshed as a result of changes in the wiki.
  • We should not abandon flexibility just because something may take a while, but we can protect someone from asking “too much” via advice rather than blocking.
  • You could also set a limit (that can be changed to a large number eg 1000)

Hi Tony,
I have updated the code with default to All years.
I have implemented the comments by @saqimtiaz

See the OP with updated code.

Still for filters like [all[tiddlers+shadows]] are pretty slow.
Strangely when you have alot of output, typing is inputbox is very laggy! This is while nothing changes for macro computing the results. I suspect that the $let may get refereshed abd cause such lags. This can be obsered when you use [all[tiddlers+shadows]] in TiddlyWiki — a non-linear personal web notebook

Note: Press Enter (shortcut) does the same actions as Set filter button.

Likely due to the sheer number of links rendered that then need to be checked for a potential refresh. Trying using a $:/temp/volatile/ prefix for the tiddler connected to the input or give it the field throttle.refresh.

Some other thoughts:

  • Displaying all years by default probably isn’t the best idea from a usability perspective either.
  • Avoid text substitution in your macros, using filters to concatenate strings instead.
  • One idea is to not calculate the years and months but rather use a default range of years/months.
  • A while back I created an alternative implementation of the sidebar lists for a colleague using $eventcatcher rather than creating links which also significantly improved performance.
    • On Chrome, using the content-visibility CSS property can also help with the initial display time for very long lists.
  • What is the use case for including shadow tiddlers? Most shadow tiddlers do not have a modified date.
1 Like

Since we’re on the topic of modified recent tabs, is there a way to have the recent tab to use the caption field with the title in <small class="tc-muted"></small>, or if there is none to use just the title?

(Along with the ability to search by month of course, as that is a very neat feature!)

Thank you for your comments!
Very useful inputs

Yes, the last year is a better choice

Absolutely. For a specific WIki, one knows this, (specially the years) in advance.

I use this only to create a long list and check performance! but you are right, only [!is[system]] is enough!

Thank you!

Why not clone recent tab and make your own? I think this is possible and I have seen solution in forum! Check also https://groups.google.com/g/tiddlywiki

Note that the timeline macro has recently been improved to make tweaking the display of titles easier: https://tiddlywiki.com/#%24%3A%2Fcore%2Fmacros%2Ftimeline

2 Likes

Hmm, I’ll give it a shot :smiley:

I had asked only because I wasn’t sure if it would conflict with what you’ve made so far.

However- I suppose testing this on my own is the fastest way to find out haha

1 Like

Yes I understand it would be slow, but I am unlikely to ever use that myself ( I don’t think others would either), even while coding I would be happy with the year based limits.

  • It is only when you are using a “sub filter” that restricts the output that one may want to see multiple years or all years.

This highlights the dilemma that emerges where a tool allows a freeform filter field, it tends to give people enough rope to do what they want and to hang themself.

I think just grabbing any old filter is not enough to understand the real world use. Remember there are a lot of almost irrational things we can do in tiddlywiki to cause a performance problem, the question is how much cotton wool we wrap around our solutions.

What If counting the number of items using the current filter is quick but the display of a large list is not quick?, perhaps the “all years” button only appears if there are less than 100 items? It is only when there are some items across multiple years when the all years becomes useful, so you don’t have to select each year one after the other.

I hope other interested users apply their change and share back to us.
I think there rooms for improvement or developing another solutions based on this.