Quantcast
Channel: DEVONtechnologies Community - Latest posts
Viewing all articles
Browse latest Browse all 16117

Most efficient way to get all nested tags (JXA)

$
0
0

Thanks for chiming in @chrillek! Totally agree the whose statements are quite clumsy. But they seem the most efficient so far. I’ve re-written your version a bit to check the difference, but the whose version is 3 times faster it seems.

(() => {
const app = Application("DEVONthink 3");
const db = app.databases['Resources'];
const tags_list = db.parents().filter(p => p.tagType() === 'ordinary tag');
tags = tags_list.map(x => x.location().replace("/Tags/","")+x.name());
tags.sort();
})();

The .sort() at the end is just for functional purposes (and to compare). These are the results:

% time osascript -l JavaScript get-tags-optimized.scpt
osascript -l JavaScript get-tags-optimized.scpt  0.05s user 0.02s system 27% cpu 0.255 total
% time osascript -l JavaScript get-tags-optimized2.scpt
osascript -l JavaScript get-tags-optimized2.scpt  0.47s user 0.03s system 72% cpu 0.690 total
% time osascript -l JavaScript get-tags-optimized3.scpt
osascript -l JavaScript get-tags-optimized3.scpt  0.19s user 0.08s system 46% cpu 0.570 total

Most obvious is that the whose statements only need two replies (as Script Editor calls them), while the .map() version needs 2 replies (location and name) for each tag (I have 273 tags in this DB).

I think I’ve reached the end of the line in terms of efficiency unless I can find I way to get two properties returned (location and name) at once. JXA is still a very functional language for this type of work, but it’s also clumsy as hell ;-



Viewing all articles
Browse latest Browse all 16117

Trending Articles