unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: William Pettersson <william@ewpettersson.se>
To: notmuch@notmuchmail.org
Subject: Python/thaw/freeze: Different references to same message
Date: Sat, 29 Jul 2017 21:58:50 +1000	[thread overview]
Message-ID: <20170729115850.ojg4uzalfyv7i64t@enigmas> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 1270 bytes --]

Hey,

I've been trying to emulate something similar to what Ben Gamari shows
in https://notmuchmail.org/pipermail/notmuch/2011/003976.html and I ran
into an issue.

That script (which admittedly is from 6 years ago) freezes messages
before changing tags. But when changing tags, new searches are often
run, returning some of the same results. It seems any changes on these
"inner" messages are lost when the outer messages are thawed, and I'm
guessing this is because the "inner" and "outer" messages reference
different objects in memory which point to the same Xapian document.

I've attached a short script which demonstrates this, to test it you
need at least one message tagged with "this_is_my_test", but the script
is fairly simple.

Now If I'm correct in guessing the issue here, I can understand that
it's not the sort of thing that is fun to fix, so I'm more looking to
see if my understanding is right. In particular, I'm asking because
clearly 6 years ago Ben's scripts worked, so maybe I'm just not
understanding them/notmuch correctly.

If I am right, then I'll just leave out the freezing/thawing. As it
stands, I'm only adding ~5-10 emails at most each run (which is every 10
minutes) so performance when adding emails isn't (yet) an issue for me.

Will

[-- Attachment #1.2: test_nm.py --]
[-- Type: text/x-python, Size: 645 bytes --]

import notmuch

db = notmuch.Database(mode=notmuch.Database.MODE.READ_WRITE)

query_str = "tag:this_is_my_test"

query1 = notmuch.Query(db, query_str)

for msg in query1.search_messages():
    msg.freeze()
    print "At start tags are %s" % ", ".join(msg.get_tags())
    msg.add_tag("added_first")
    query2 = notmuch.Query(db, query_str)
    for msg2 in query2.search_messages():
        msg2.freeze()
        msg2.add_tag("added_second")
        msg2.thaw()
        print "Inside inner loop tags are %s" % ", ".join(msg2.get_tags())
    msg.thaw()
    print "At end tags are %s" % ", ".join(msg.get_tags())
    msg.remove_tag("added_first")


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

             reply	other threads:[~2017-07-29 12:06 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-29 11:58 William Pettersson [this message]
2017-07-31 21:20 ` Python/thaw/freeze: Different references to same message David Bremner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170729115850.ojg4uzalfyv7i64t@enigmas \
    --to=william@ewpettersson.se \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).