Custom Columns - VF and Single Run of a section

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
nerdweed
Posts: 648
Joined: 25 Feb 2012 07:47

Custom Columns - VF and Single Run of a section

Post by nerdweed »

Happy New XYear

1. Is it possible to set a Visual Filter on Custom Scripted Column

2. As the scripts for custom column, run per file, how do you run a section of code only once. My scripted column pulls data from a file for that folder (intended to do once - cache it) and then works out values for individual files from that cached. I tried two methods, and don't like them much
a. Time Difference - If the code was run within the previous 60 seconds, don't run that global piece of code. Otherwise run that piece of code and update the previous run time. (Thanks to TheQwerty)
b. Folder Path - Set a perm variable to the current folder path. If the path is different run the global code and update the perm var.

I hate method a, because it is difficult to identify, if it is working on stale cache (cache was for a different folder)
Method b is disliked, because I need to unset the variable if the contents of the files are changed or else it continues to work on a stale cache.

Obvious solution would be try a combination of both, but it would almost double the time for script execution and hence cancelled out.

Do you have some other tricks in your sleeves.

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Custom Columns - VF and Single Run of a section

Post by TheQwerty »

nerdweed wrote:Happy New XYear
Happy New XYear to you too!
nerdweed wrote:1. Is it possible to set a Visual Filter on Custom Scripted Column
Unfortunately not. It is possible to filter on Extra Tag Columns though, so you could have the CSC tag the items if you absolutely must filter.
nerdweed wrote:2. As the scripts for custom column, run per file, how do you run a section of code only once. My scripted column pulls data from a file for that folder (intended to do once - cache it) and then works out values for individual files from that cached. I tried two methods, and don't like them much
a. Time Difference - If the code was run within the previous 60 seconds, don't run that global piece of code. Otherwise run that piece of code and update the previous run time. (Thanks to TheQwerty)
b. Folder Path - Set a perm variable to the current folder path. If the path is different run the global code and update the perm var.

I hate method a, because it is difficult to identify, if it is working on stale cache (cache was for a different folder)
Method b is disliked, because I need to unset the variable if the contents of the files are changed or else it continues to work on a stale cache.

Obvious solution would be try a combination of both, but it would almost double the time for script execution and hence cancelled out.

Do you have some other tricks in your sleeves.
A combination of the two shouldn't necessarily double the execution time, it will be longer but it all depends on what you're using to identify the running instance/when to trigger the resource heavy portion of the script.

Instead of the time difference you could use the Folder Path + the data file's modification time or if it is small enough its hash. You could then track this for multiple paths in a permanent variable or a separate data file - but you'll need to play around a bit to figure out what you find as an acceptable speed trade-off.


I think a more elegant solution would be to set your Custom Column Script to only run on the data file itself, and then have it set Extra Tag Columns for the individual items. With this you could set the Extra Tag for the data file to the modification time or hash and use that for a comparison to detect when the script needs to update the tags. This has the added benefit of if you show only the Extra Column(s) and not the Custom Column Script then you effectively have a cache-only mode. Unfortunately this tactic requires having two columns visible, one of which is blank for all but one item; though you're free to re-use this column or combine it in a mixed column to make it more useful. It also means possibly bloating your tags.dat.


A not very good option would be to use the PFADefaultOpenFolders tweak and then you can define a PFA for the folder (or all folders) and have a script run when you open that folder. This has its own shortcomings though as it will only run when you open the folder - browsing via Favorites/Address Bar/Tree/anything that does a goto won't trigger the script. Then when "opening" the folder you parse the file, update Extra Tags, and then goto the folder.


Maybe a new Custom Column script type of "Run-Once Script" could be introduced, but this needs some thought into how it plays with the trigger modes and search results/listings from multiple locations. I imagine eventually CEA could improve things but only time will tell.

nerdweed
Posts: 648
Joined: 25 Feb 2012 07:47

Re: Custom Columns - VF and Single Run of a section

Post by nerdweed »

Thanks TheQwerty for your concise answers as always. I have around half a million items that are tagged now (externally). XY was using around 350 MB with around 150 thousand entries. So I moved towards a SQLite solution. So using Extra Tags isn't an option.
A combination of the two shouldn't necessarily double the execution time, it will be longer but it all depends on what you're using to identify the running instance/when to trigger the resource heavy portion of the script.
True, it won't exactly double in most cases. This was a bad approximation. Since, the actual execution only involves a formatlist and gettoken, the impact of double checks is noticeable. (Already tried)
Instead of the time difference you could use the Folder Path + the data file's modification time or if it is small enough its hash. You could then track this for multiple paths in a permanent variable or a separate data file - but you'll need to play around a bit to figure out what you find as an acceptable speed trade-off.
Checking the modification time is a good idea but maybe having a shorter time difference would still be better for my use case. I will still give it a try
A not very good option would be to use the PFADefaultOpenFolders tweak and then you can define a PFA for the folder (or all folders) and have a script run when you open that folder. This has its own shortcomings though as it will only run when you open the folder - browsing via Favorites/Address Bar/Tree/anything that does a goto won't trigger the script. Then when "opening" the folder you parse the file, update Extra Tags, and then goto the folder.
I don't need to do this if I check for the folderpath as the script anyways refetches the data when the folder is changed. I am currently using a catalog script that unsets the variable containing the folder name to force a refetch of data. Not something, I like to do though.
Maybe a new Custom Column script type of "Run-Once Script" could be introduced, but this needs some thought into how it plays with the trigger modes and search results/listings from multiple locations. I imagine eventually CEA could improve things but only time will tell.
I trust you mean "Run-Once" section in each script rather than trigger because it doesn't make sense as a trigger. If at all this is possible, all triggers can utilise it.

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Custom Columns - VF and Single Run of a section

Post by TheQwerty »

nerdweed wrote:
Maybe a new Custom Column script type of "Run-Once Script" could be introduced, but this needs some thought into how it plays with the trigger modes and search results/listings from multiple locations. I imagine eventually CEA could improve things but only time will tell.
I trust you mean "Run-Once" section in each script rather than trigger because it doesn't make sense as a trigger. If at all this is possible, all triggers can utilise it.
I was suggesting a way to run a script once on browse regardless of the number of items. It's more for running the script once to populate the Extra Tags (even if that doesn't work for you).


I suppose Don could do something where XY checks the column script for "_Initialize" or "_Terminate" labels and runs the former before running any one row's script, and the latter after all rows. But this might get kind of tricky with the Click trigger, is kind of hacky, and I obviously have no idea of the performance impact this might have.

It might be better to have dedicated fields for those scripts in the Configure Custom Column dialog, but that breaks the storage structure.


Though again I think CEA could really help here, so maybe we're just delaying the best solution by side-tracking Don with ugly workarounds?

nerdweed
Posts: 648
Joined: 25 Feb 2012 07:47

Re: Custom Columns - VF and Single Run of a section

Post by nerdweed »

No, let Don focus on CEA instead.

OTOH, Quick Search works on custom columns. Could this support be added to VF.

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Custom Columns - VF and Single Run of a section

Post by TheQwerty »

nerdweed wrote:OTOH, Quick Search works on custom columns. Could this support be added to VF.
Give this a try:

Code: Select all

"Filter by Quick Search"
  // Prompt user for search query.
  $query = Input('Query Current List',,'Dimensions: > 1020 AND Dimensions: < 1980');

  // Search current list.
  $results = QuickSearch($query, '#', '|', 's');

  End $results == '', 'No results found.';

  // VF does not support paths so...
  // Reduce the results to just their names.
  $results = Report('|{Name}', $results);
  $results = SubStr($results, 1);  // Trim leading pipe.

  // Escape wildcards which might be in the names.
  $results = RegexReplace($results, '([?*#[])','[$1]');

  // Give the filter a nice caption.
  $results = """Quick Search Results: $query"" $results";

  // FILTER!!!!
  Filter $results;

nerdweed
Posts: 648
Joined: 25 Feb 2012 07:47

Re: Custom Columns - VF and Single Run of a section

Post by nerdweed »

Thanks Qwerty. This does a quick search and then does a filter on the listed files. Quick search forgets the populated custom columns (and for some odd reason I thought VF doesn't - my bad as VF forgets it as well). I had tried VF where the custom column were set with trigger mode as browse and quick search with trigger as Click causing this confusion.

So I don't mind doing a Quick Search either.

Thanks for the script again. Though I won't be using in this case, but it will prove useful when I need to use QuickSearch from within some script.

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Custom Columns - VF and Single Run of a section

Post by TheQwerty »

What about using a script to apply color filters?

Use Report() to get the items and column data.
Reduce those results based on your Search/VF criteria - most likely using a loop but you might be lucky and able to use FormatList's filter.
Highlight the matching items with ColorFilter().

Not knowing anything about your column data or filter criteria makes that a bit of a challenge. :P
It shouldn't be too hard to script though. ;)

This old script might provide a decent starting point - assuming it still works anyhow. :whistle:

nerdweed
Posts: 648
Joined: 25 Feb 2012 07:47

Re: Custom Columns - VF and Single Run of a section

Post by nerdweed »

My custom column is simple. I have a sqlite database from which I bring out the details for each of the files in that folder. I wanted to filter out those files which have particular values (no fixed criteria). As the populated column is mix of multiple fields, color filters won't be very useful. Basically, tag.data became tag.txt and tags, labels, comments + extra tags are being populated over a mixed column.

Please do not waste more time on this.

Code: Select all

If ($CC_EXEC != <cc_path>)
{
 perm $CC_DATA = runret("cmd /c sqlite3.exe Tag.db ""<query>""", $HOME);
 perm $CC_EXEC = <cc_path>;
 $CC_DATA = replace($CC_DATA, <cc_path>);
}
return trim(gettoken(formatlist("$CC_DATA", "f", "<crlf>", "<cc_name>|*"), 2, "|", ,2), "|", "LR");

Post Reply