I want to add values to a custom column in the same way the folder size shortcut updates the size values—processing files parallelly. So far I only managed to get my script to work by adding values to a item at a time.
In my case all the values for the items can be passed from an executable (it can handle the calculation parallelly) and therefor the values can be available at once. So is there a way to pass all those values to the custom column at once.
Folder size isn't calculated in parallel. (The bottleneck is the storage and filesystem, not adding the numbers up on the CPU, so requesting the information in parallel would be slower, at least on device types where it wouldn't be very fast via both methods.)
Scripts can use variables to store information if it has already been calculated and will be useful for another item. Either normal script-language global variables (which will persist until the script goes idle) or Opus vars (which can persist for longer, but probably don't make as much sense here). You can use those to store a cache of data and only re-calculate the information if the cache is empty, old, or doesn't have information for the requested file/folder.
What I'm trying to do is to create a word count custom column for text files that works faster than Column: Pandoc Word Count. I created a golang excutable that uses doctotext to output (either stdout or for temporary text file) the word counts of the files passed to it quickly.
Have you tried doing it the simple way first? It often turns out to be fast enough.
Unless the word-counting program has a lot of start-up overhead (which would be strange for something so simple), it isn't likely to matter if it's run once for all files or once per file.
I did it one file at a time. It's faster than using pandoc but it still took around 25 seconds or so for one of my folders that had about 60 text files. (pandoc one took 33 seconds). But it takes only second or two to get those values from the executable. I asked because the way folder size shortcut adds values really quickly was much better than what I'm seeing in my script right now, and to see if I could do it too.
I don't think caching is necessary. I'm trying to do the calculation once (or few times as possible because the cmd max line length) for multiple files and store it in a temporary json file. Then I just have to read that json file once and col.method function can be made much simpler.
How can I access the file paths in the active tab (to pass multiple file path arguments to the executable like I showed in the example) before col.method function?
I managed to do it! Now it only takes a couple of seconds to add word counts for text files of the said folder. Now it works quickly just like how the folder size shortcut works!