unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Tomi Ollila <tomi.ollila@iki.fi>
To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org
Subject: Re: [PATCH v2] CLI/git: opportunistically use bindings to check for known messages
Date: Sat, 16 Jul 2022 22:23:29 +0300	[thread overview]
Message-ID: <y3f4g3a.utffxy-too@iki.fi> (raw)
In-Reply-To: <20220715144301.793133-1-david@tethera.net>

On Fri, Jul 15 2022, David Bremner wrote:

> If the bindings are installed, use them to avoid one exec of notmuch
> search per message.

tnx. continues to work for me where I have symlink to nmbug in ~/bin/.
some time in the future i'll investigate whether i get 
python3 path/to/nmbug.zip ... working but not today...

the series looks good to me.

Tomi

> ---
>  notmuch-git.py | 33 ++++++++++++++++++++++++++++-----
>  1 file changed, 28 insertions(+), 5 deletions(-)
>
> I decided to leave the old (slow) path in for now, since it is fast
> enough for use of nmbug to manage notmuch developement tags.
>
>
> diff --git a/notmuch-git.py b/notmuch-git.py
> index 4d9887c8..ceb86fbc 100644
> --- a/notmuch-git.py
> +++ b/notmuch-git.py
> @@ -698,6 +698,32 @@ def _is_unmerged(ref='@{upstream}'):
>          stdout=_subprocess.PIPE, wait=True)
>      return base != fetch_head
>  
> +class DatabaseCache:
> +    def __init__(self):
> +        try:
> +            from notmuch2 import Database
> +            self._notmuch = Database()
> +        except ImportError:
> +            self._notmuch = None
> +        self._known = {}
> +
> +    def known(self,id):
> +        if id in self._known:
> +            return self._known[id];
> +
> +        if self._notmuch:
> +            try:
> +                _ = self._notmuch.find(id)
> +                self._known[id] = True
> +            except LookupError:
> +                self._known[id] = False
> +        else:
> +            (_, stdout, stderr) = _spawn(
> +                args=['notmuch', 'search', '--output=files', 'id:{0}'.format(id)],
> +                stdout=_subprocess.PIPE,
> +                wait=True)
> +            self._known[id] = stdout != None
> +        return self._known[id]
>  
>  @timed
>  def get_status():
> @@ -705,14 +731,11 @@ def get_status():
>          'deleted': {},
>          'missing': {},
>          }
> +    db = DatabaseCache()
>      with PrivateIndex(repo=NOTMUCH_GIT_DIR, prefix=TAG_PREFIX) as index:
>          maybe_deleted = index.diff(filter='D')
>          for id, tags in maybe_deleted.items():
> -            (_, stdout, stderr) = _spawn(
> -                args=['notmuch', 'search', '--output=files', 'id:{0}'.format(id)],
> -                stdout=_subprocess.PIPE,
> -                wait=True)
> -            if stdout:
> +            if db.known(id):
>                  status['deleted'][id] = tags
>              else:
>                  status['missing'][id] = tags
> -- 
> 2.35.1
>
> _______________________________________________
> notmuch mailing list -- notmuch@notmuchmail.org
> To unsubscribe send an email to notmuch-leave@notmuchmail.org

  reply	other threads:[~2022-07-16 19:23 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-03 15:10 performance improvements for notmuch git checkout David Bremner
2022-07-03 15:11 ` [PATCH 1/4] debian: add git as a build-dependency, for the test suite David Bremner
2022-07-07 10:30   ` David Bremner
2022-07-03 15:11 ` [PATCH 2/4] perf-test: add tests for notmuch-git David Bremner
2022-07-05 16:40   ` Tomi Ollila
2022-07-07  9:47     ` David Bremner
2022-07-03 15:11 ` [PATCH 3/4] CLI/git: current cache contents (file list) of index David Bremner
2022-07-03 15:11 ` [PATCH 4/4] CLI/git: replace calls to notmuch-search with database access David Bremner
2022-07-07 14:51   ` Tomi Ollila
2022-07-07 15:59     ` David Bremner
2022-07-09 19:35       ` Michael J Gruber
2022-07-15 14:43   ` [PATCH v2] CLI/git: opportunistically use bindings to check for known messages David Bremner
2022-07-16 19:23     ` Tomi Ollila [this message]
2022-07-17  0:51       ` 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=y3f4g3a.utffxy-too@iki.fi \
    --to=tomi.ollila@iki.fi \
    --cc=david@tethera.net \
    --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).