unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* Python/thaw/freeze: Different references to same message
@ 2017-07-29 11:58 William Pettersson
  2017-07-31 21:20 ` David Bremner
  0 siblings, 1 reply; 2+ messages in thread
From: William Pettersson @ 2017-07-29 11:58 UTC (permalink / raw)
  To: notmuch


[-- 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 --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Python/thaw/freeze: Different references to same message
  2017-07-29 11:58 Python/thaw/freeze: Different references to same message William Pettersson
@ 2017-07-31 21:20 ` David Bremner
  0 siblings, 0 replies; 2+ messages in thread
From: David Bremner @ 2017-07-31 21:20 UTC (permalink / raw)
  To: William Pettersson, notmuch

William Pettersson <william@ewpettersson.se> writes:

> 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.

That sounds likely to be the case. There's no attempt to synchronize
multiple in memory caches of the same xapian document.

> 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.

You might try begin_atomic / end_atomic instead. These nest properly by
design, although I'm not so confident about the performance impact
(they're not really focussed on performance).

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-07-31 21:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-29 11:58 Python/thaw/freeze: Different references to same message William Pettersson
2017-07-31 21:20 ` David Bremner

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).