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

I would not overdo the whose. It’s a bit clumsy, and JavaScript’s filter looks cleaner to me.

What about this:

(() => {
  const app = Application("DEVONthink 3");
  const db = app.databases['YOURDATABASE'];
  const tagLocations = db.parents()
      .filter(p => p.tagType() === 'ordinary tag' && p.tags().length )
      .map(t => { 
	   const n = t.name();
	   return {tag: n, location: t.location().replace('/Tags/','') + n}});

  const tags_list = tagLocations.sort((a,b) => a.tag > b.tag ? 1 : (a.tag < b.tag ? -1 : 0));
  console.log(tags_list.map(t => `${t.tag}: ${t.location}`).join('\n'));
  })()

I seems to do what you want, though I’m not 100 percent sure of that.
Main differences

  • Only one run over db.parents()
  • Doesn’t use whose
  • Builds only one array tagLocations, consisting of {tag: tagName, location: tagLocation} objects.

I’m not quite sure what your last sort().map() sequence is doing (apart from the sort, that is). And I didn’t benchmark that – I have only about 34 tags in the DB I could use for testing.


Viewing all articles
Browse latest Browse all 16117

Trending Articles