recentTags() returns tags which dont exist anymore

#1

I wanted to build actions for tagging drafts.
I want to get all existing tags in drafts - since i did not found any function to retrieve them all at once (would be a great feature!), I started to create an action which will filter all the drafts and add all their tags to an array, to jump over all the recent ones I used Draft.recentTags() and its returning tags which dont exist anymore and are not displayed in the filter view.

0 Likes

#2

FWIW, I use this.

function allTags()
{
	return [...new Set([].concat(...Draft.query("", "all", []).map((currentDraft) => currentDraft.tags)))].sort();
}

alert(allTags().toString());
1 Like

#3

thank you, I’m not very familiar with JavaScript I did this:

var tags = new Set();
  var ws = Workspace.create();
  var leftDrafts = ws.query("all");
  while (leftDrafts.length > 0) {
    if (leftDrafts[0].tags != 0) {
      let thisDraftsTags = leftDrafts[0].tags;
      for (tag in thisDraftsTags) {
        tags.add(thisDraftsTags[tag]);
      }
    }
    leftDrafts.shift();
  }

I’d guess that your version is a lot faster I’ll try it, thank you!

0 Likes

#4

I’ve never actually speed tested it. I have just under 300 drafts returned under ‘all’ and fewer than 20 tags. It certainly runs fast enough for my purposes, but I suspect any native solution running against Drafts’ database of notes may well run faster. Certainly using your function and converting the results to an array and sorting them, and comparing against the function I’m using, both run very quickly and so fast on my data and devices, I can’t determine which is faster.

0 Likes

#5

yep I tested it, too and could not recognize a real difference :slight_smile: as long as its working that’s fine for me :wink:

0 Likes