Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 538D3431FD0 for ; Thu, 2 Jun 2011 07:20:21 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.09 X-Spam-Level: X-Spam-Status: No, score=-0.09 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, T_MIME_NO_TEXT=0.01] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 33hTjFNPDyN2 for ; Thu, 2 Jun 2011 07:20:20 -0700 (PDT) Received: from homiemail-a75.g.dreamhost.com (caiajhbdccah.dreamhost.com [208.97.132.207]) by olra.theworths.org (Postfix) with ESMTP id 6BC4F431FB6 for ; Thu, 2 Jun 2011 07:20:20 -0700 (PDT) Received: from homiemail-a75.g.dreamhost.com (localhost [127.0.0.1]) by homiemail-a75.g.dreamhost.com (Postfix) with ESMTP id B5F575EC084; Thu, 2 Jun 2011 07:20:19 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=SSpaeth.de; h=from:to:subject :in-reply-to:references:date:message-id:mime-version: content-type; q=dns; s=sspaeth.de; b=QU8B0jbQUKX+1bOQ9YDkRBUpjwi WHtJo5sglyEoi9KZSTf1OxLaEDPi/U3cGPQkCNIMuXSBYr3B/gWmEaTQPi5L9S/8 yUzlAQ5cElWdHRxGsbiyqBDP2mBtKGIzSjEtrL1EzfCTNu1sWW9OQhwFDn9+yXbW FHdESGzTtpIim1wo= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=SSpaeth.de; h=from:to :subject:in-reply-to:references:date:message-id:mime-version: content-type; s=sspaeth.de; bh=1tMr6XP+VRw8lTz3LzUX3PuAc3I=; b=d g3rp1RGWNYRHlRi2EshqlY6WZsdtbjCY414QrrJbwumriLPVs74ZT06fn/nVwEcB jjWzYzAj+aFNnsEe+6hEOsKNjGeHLJeT3I8jgJ0dI2NTqtYb0XwEKgBHFKmX9KgM v3vp2XGeUU4kJ+8Qb6XMolbpgfpFXxlYPDXpRry9uE= Received: from spaetzbook.sspaeth.de (unknown [194.204.5.155]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: fax@sspaeth.de) by homiemail-a75.g.dreamhost.com (Postfix) with ESMTPSA id EEF535EC07E; Thu, 2 Jun 2011 07:20:17 -0700 (PDT) Received: by spaetzbook.sspaeth.de (sSMTP sendmail emulation); Thu, 02 Jun 2011 16:20:15 +0200 From: Sebastian Spaeth To: Brian May , notmuch Subject: Re: [python] get all messages of a thread In-Reply-To: References: <1306588052-sup-9838@brick> <87aae07lxi.fsf@SSpaeth.de> User-Agent: Notmuch/0.5-209-gc8b5718 (http://notmuchmail.org) Emacs/23.2.1 (x86_64-pc-linux-gnu) Date: Thu, 02 Jun 2011 16:20:14 +0200 Message-ID: <87r57cuxgh.fsf@SSpaeth.de> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 02 Jun 2011 14:20:21 -0000 --=-=-= Content-Transfer-Encoding: quoted-printable On Thu, 2 Jun 2011 19:43:29 +1000, Brian May wrote: > On 2 June 2011 17:05, Sebastian Spaeth wrote: >=20 > > What would be the best way to solve this (besides fixing the C api to > > allow to reset the iterator ;-) ?) > * It is not easy to fix the C api to reset the iterator (what about > repeating the search?) I am not sure about the difficulty of that, I am not a C-kind of guy. Repeating the search would be easy but potentially gives you different results since the db could have changed since then. =20 > * The only accurate way to get the number of messages is to iterate throu= gh > every search result and count them? There is count_messages() which wraps notmuch_query_count_messages which invokes some very quick xapian function. But the xapian docs explicitely state that it's xapians best guess and not guaranteed to be the real number of messages (although it always was in my attempts). And you don't want len() to return an approximation of the iterator length.... > If so, then len(...) I think might be very slow if there are a large numb= er > of elements. =20 > Maybe it might be easier/better to implement object.__nonzero__(self) > instead of the object.__len__(self) method? >=20 > http://docs.python.org/reference/datamodel.html >=20 > object.__nonzero__(self) > Called to implement truth value testing and the built-in operation bool(); > should return False or True, or their integer equivalents 0 or 1. When th= is > method is not defined, __len__() is called, if it is defined, and the obj= ect > is considered true if its result is nonzero. If a class defines neither > __len__() nor __nonzero__(), all its instances are considered true. Interesting, did not know about this one. I guess that would solve the example with the: t =3D query.search_threads() if t: for thread in t: print thread Actually the "if t:" is no longer needed, I just tried a query returning no Threads and=20 for thread in threads: pass works just fine with an empty Threads() object. I made the change, and implemented __nonzero__ and removed the len() method. It just doesn't make sense on 1-time iterators. (I documented the change in the API docs). Sorry if this breaks existing code. list(Threads()) works just fine too, it just took a while to create a list of 13k Thread() objects on this laptop. (and list() will of course not return until it is finished). Sebastian --=-=-= Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) iEYEARECAAYFAk3nnB4ACgkQVYX1jMgnoGIRMgCeOMJq2ej5K9/WXtxMLMjD02lo HJoAn1BMBhRczltfWmOI/GQkquUv8WdB =T4tg -----END PGP SIGNATURE----- --=-=-=--