def tags(self): """Return an immutable set with all tags used in this database. This returns an immutable set-like object implementing the collections.abc.Set Abstract Base Class. Due to the underlying libnotmuch implementation some operations have different performance characteristics then plain set objects. Mainly any lookup operation is O(n) rather then O(1). Normal usage treats tags as UTF-8 encoded unicode strings so they are exposed to Python as normal unicode string objects. If you need to handle tags stored in libnotmuch which are not valid unicode do check the :class:`ImmutableTagSet` docs for how to handle this. :rtype: ImmutableTagSet :raises ObjectDestroyedError: if used after destroyed. """ try: ref = self._cached_tagset except AttributeError: tagset = None else: tagset = ref() if tagset is None: tagset = tags.ImmutableTagSet( self, '_db_p', capi.lib.notmuch_database_get_all_tags) self._cached_tagset = weakref.ref(tagset) return tagset
def collect_tags(self): """Return the tags of messages matching this query.""" msgs_pp = capi.ffi.new('notmuch_messages_t**') ret = capi.lib.notmuch_query_search_messages(self._query_p, msgs_pp) if ret != capi.lib.NOTMUCH_STATUS_SUCCESS: raise errors.NotmuchError(ret) self._msgs_p = msgs_pp[0] tagset = tags.ImmutableTagSet(self, '_msgs_p', capi.lib.notmuch_messages_collect_tags) return tags.ImmutableTagSet._from_iterable(tagset)