[notmuch] Rather simple optimization for notmuch tag
olly at survex.com
Tue Dec 22 19:45:14 PST 2009
Carl Worth writes:
> On Fri, 18 Dec 2009 00:49:00 -0700, Mark Anderson wrote:
> > I was updating my poll script that tags messages, and a common idiom is
> > to put
> > tag +mytag <search_terms> and not tag:mytag
> > I don't know anything about efficiency, but for the simple single-tag
> > case, couldn't we imply the "and not tag:mytag" from the +mytag action
> > list for the tag command?
> On one level, it really shouldn't be a performance issue to tag messages
> that already have a particular tag. (And in fact, the recently proposed
> patches to fix Xapian defect 250 even address this I think.)
Applying a filter up-front like this is likely to still help I think as it
avoids Xapian having to reverse-engineer this information internally.
> One potential snag with both ideas is that the "notmuch tag"
> command-line as currently implemented allows for multiple tag additions
> and removals with a single search. So the optimization here couldn't be
> used unless there was just a single tag action.
Actually, you could do this with multiple tags - you just need to build
a filter for documents which might be affected.
So if you're adding tags a1 and a2, you want: <query> AND_NOT (a1 AND a2)
since documents which already have tags a1 and a2 can be ignored.
If you're removing d1 and d2, then the filter is: <query> AND (d1 OR d2)
since documents have to be tagged d1 or d2 in order for the removal to
Handling a combination of removals and additions is trickier, but probably
possible, although the more tags you are dealing with, the less profitable
the filtering is likely to be (as the filter is likely to cull fewer
documents yet be more expensive to evaluate).
More information about the notmuch