Tobias' Delete All Tiddlers By Filter

259 views
Skip to first unread message

codacoder...@outlook.com

unread,
Aug 10, 2017, 12:21:29 PM8/10/17
to tiddl...@googlegroups.com
I stumbled across this and thought it would make a good starting point for a JS macro.  Having tried it on a couple of TWs (where I had a ton of archaic temp/state tiddlers I wanted to remove) it seems there is a very destructive bug in there somewhere -- it destroys the TW (and since the wikis have passwords, they will no longer decrypt).  The size of one of the wikis went from ~6.5MB to 103KB.  Ouch.

Here is Tobias' original code:

var filter = "tag[FOO]";
filter
= "[all[tiddlers]!prefix[$]" + subfilter + "]";
var tids = $tw.wiki.filterTiddlers(filter, null);
if(confirm('Delete all ' + tids.length + '?\n\n' + tids)){
 
for(var t=0; t<tids.length; t++) {
    $tw
.wiki.deleteTiddler(tids[t]);
 
}
}


Noticing the stray subfilter variable, I cleaned it up and then used this:

var filter = "[prefix[$:/temp/state/1]]";
var tids = $tw.wiki.filterTiddlers(filter, null);
if(confirm('Delete all ' + tids.length + '?\n\n' + tids)){
 
for(var t=0; t<tids.length; t++) {
    $tw
.wiki.deleteTiddler(tids[t]);
 
}
}


If I use that filter in the filter search input in TW, it works as expected. When running the code above, it lists the exact same tiddlers (AFAICT), yet, it destroys the TW on confirming the dialog.

Anyone see a problem? What am I missing?

TIA


Edited to change 6.5KB to 6.5MB (oops)

PMario

unread,
Aug 10, 2017, 12:50:39 PM8/10/17
to TiddlyWiki
Hi,
Try this one: https://wikilabs.github.io/editions/remove-states/ ... it shouldn't be that destructive, because you can see, what you delete.
-m

codacoder...@outlook.com

unread,
Aug 10, 2017, 1:27:46 PM8/10/17
to TiddlyWiki
Cool.  Thanks Mario!

@TiddlyTweeter

unread,
Aug 14, 2017, 5:49:00 AM8/14/17
to TiddlyWiki
Ciao PMario

First time I ever seen that. So much good stuff has been written you can't find ...

Tobias also did a similar thing with individually clickable items to delete--however that has NO option to delete ALL, unlike yours.

Could yours (its just a single macro, right, not a plugin with dependencies?) be re-factored to accept ANY filter through an input field?

Just wishes :-)
Best
Josiah

PMario

unread,
Aug 14, 2017, 7:01:53 AM8/14/17
to TiddlyWiki
On Monday, August 14, 2017 at 11:49:00 AM UTC+2, @TiddlyTweeter wrote:
Could yours (its just a single macro, right, not a plugin with dependencies?) be re-factored to accept ANY filter through an input field?

Sure, ...
_but_ it would be very destructive and error prone.

eg: If there is a typo.

 - Let's imagine a filter like: [prefix[$:/temp]]
 - it will also delete $:/temptation
 - which may not be intended.

 ... Do you see the the missing char in the filter variable? .. and this example contains an obvious problem. Filters can have side-effects, that are much harder to spot.

I know, that's a user problem, if s/he creates a filter that dosn't do what is intended, or if a filter has unintended side-effects ...  I think the plugin contains enough info, that users can create their own variations of the macro, that work for their specific usecase.

I personally don't want to be responsible, if my plugin deletes stuff that the user wanted to keep.

So everyone, which wants to be responsible can jump in here.

have fun!
mario

@TiddlyTweeter

unread,
Aug 14, 2017, 7:17:25 AM8/14/17
to TiddlyWiki
Its an interesting point you bring up.

IMO if you don't constantly backup your TW you are asking for trouble--sooner or later.

I have experienced a couple of macros that ATE MY WIKI.

I'm not sure that the line of defence is to NOT give us The Powerful Wizard Of Utility. But, rather, perhaps, to deliver the Wizard with levels of warnings ... (1) Do NOT do this unless you have a backup. So don't blame me if it eats your Wiki. (2) Are you REALLY sure you want to do this?

There needs to be room for brave people too.

Josiah, x

PMario

unread,
Aug 14, 2017, 7:52:55 AM8/14/17
to TiddlyWiki
On Monday, August 14, 2017 at 1:17:25 PM UTC+2, @TiddlyTweeter wrote:
IMO if you don't constantly backup your TW you are asking for trouble--sooner or later.

That's right. ... 3 weeks ago my win HD died. Luckily I did back up the data partition some days earlier. Now I have a physical system and 2 mirrored data drives. plus the existing backup solution :)
 
I have experienced a couple of macros that ATE MY WIKI.

Then you know what I mean :)
 
I'm not sure that the line of defence is to NOT give us The Powerful Wizard Of Utility. But, rather, perhaps, to deliver the Wizard with levels of warnings ... (1) Do NOT do this unless you have a backup. So don't blame me if it eats your Wiki. (2) Are you REALLY sure you want to do this?

That's exactly the point.

As a developer I don't want to do harm. So if I would release a plugin that can have destructive side effects, I need / want to take care, that the user knows, what is going on. So it needs to be configurable: Similar to the "bundler plugin". Bundler even doesn't delete stuff, but imports can overwrite existing tiddlers ...

 
There needs to be room for brave people too.

Sure. ... If there wouldn't be murphy's law: "Anything that can go wrong will go wrong!"

At the moment we don't have a "tm-ask-and-delete-message" needed for your "(2) Are you REALLY sure you want to do this?" ... At least I think there isn't. ... So may be we need one. ... But for my personal usage the security questions would need to be switched off. ... because I hate popups ;)

have fun!
mario

PMario

unread,
Aug 14, 2017, 8:03:28 AM8/14/17
to TiddlyWiki
On Monday, August 14, 2017 at 1:52:55 PM UTC+2, PMario wrote:
At the moment we don't have a "tm-ask-and-delete-message" needed for your "(2) Are you REALLY sure you want to do this?" ... At least I think there isn't. ...

I was wrong: http://tiddlywiki.com/prerelease/#%24%3A%2Fcore%2Fui%2FAdvancedSearch%2FFilter%2FFilterButtons%2Fdelete
...
So just open the control panel: select filter:  .... and hit the delete button.

Just checked my plugin, and saw, that I deprecated it already. ... That's probably the reason.

-m
 

@TiddlyTweeter

unread,
Aug 14, 2017, 8:13:31 AM8/14/17
to TiddlyWiki
Ciao PMario,

HA!

My point is YOUR approach is LESS dangerous than that in the actual release under Advanced Search > Filter > Delete.

SO, your gizmo revised to allow filters would be a plus IMO. I'd trust it MORE than the Standard.

Best wishes
Josiah

TonyM

unread,
Aug 15, 2017, 10:14:46 PM8/15/17
to TiddlyWiki
Mario,

Actually your bundler pluginhttps://wikilabs.github.io/editions/bundler/ .goes a long way to showing how you can reduce the effect or stray filters by counting the number of tiddlers selected. I could see an option to delete the same filtered set of tiddlers after export. This would mean forcing a group of tiddlers to be exported before deletion so there will be no regrets. I used to do that in TWC exporting TRASHED items before I emptied the Trash.

PS Condolences on the loss of a HD. Very sad event. :)

Tony

.

@TiddlyTweeter

unread,
Aug 16, 2017, 6:02:32 AM8/16/17
to TiddlyWiki
Ciao PMario & Tony M

I agree with Tony. As I mentioned before in the Bundler thread using the "Bundle List" rapidly makes you aware that its approach (its precision in listing, its persistence, its ease of use) illustrates a way of working that great enhances import/export.

Whether a DESTROYER could be integrated with it, or whether a similar complementary approach could be done for deletion I don't know. What I can see is that that Bundler & Destroyer in harmony could really ease bulk procedures and make them a lot safer.

Mario, I like your https://wikilabs.github.io/editions/remove-states/ (example approach) over the Advanced Search delete button because its offers both BULK & individual item control whilst deleting. Perhaps something like that could be scaled of the Bundler approach?


TonyM wrote:
your bundler pluginhttps://wikilabs.github.io/editions/bundler/ .goes a long way to showing how you can reduce the effect or stray filters by counting the number of tiddlers selected. I could see an option to delete the same filtered set of tiddlers after export.

Buongiorno
Josiah

PMario

unread,
Aug 16, 2017, 6:15:08 AM8/16/17
to TiddlyWiki
On Wednesday, August 16, 2017 at 12:02:32 PM UTC+2, @TiddlyTweeter wrote:
Mario, I like your https://wikilabs.github.io/editions/remove-states/ (example approach) over the Advanced Search delete button because its offers both BULK & individual item control whilst deleting. Perhaps something like that could be scaled of the Bundler approach?

I think, I can add a DESTROYER function, and reuse the core "Are you sure" dialog. ..

I also consider to implement a possibility to "comment" in bunder config tiddlers. .. TW can handle the .multids tiddler format "application/x-tiddlers", which already knows, how to deal with comments. ... BUT I'm not sure atm, how I want to implement it. .. I'd like to improve the "enlist" operator, so the bundler plugin can stay simple. We'll have to see, what Jeremy says.

In the mean time I could implement a temporary operator for testing.

-mario
Reply all
Reply to author
Forward
0 new messages