From 0ef246cf77f0ed1f8fa7f648ec2b63ebe6e99a44 Mon Sep 17 00:00:00 2001 From: Hugo Osvaldo Barrera Date: Sat, 6 Jul 2024 21:58:23 +0200 Subject: notmuch: remove redundant query This function first queried the notmuch database for a single filename (arbitrarily chosen), and then queried the database for all filenames of the same message. Drop one unnecessary query; only query all names, and then use the first one as an arbitrarily chosen one. Signed-off-by: Hugo Osvaldo Barrera Reviewed-by: Bence Ferdinandy Acked-by: Robin Jarry --- worker/notmuch/message.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'worker') diff --git a/worker/notmuch/message.go b/worker/notmuch/message.go index daaec7d0..b73f1888 100644 --- a/worker/notmuch/message.go +++ b/worker/notmuch/message.go @@ -41,17 +41,16 @@ func (m *Message) MessageInfo() (*models.MessageInfo, error) { if err != nil { return nil, err } - // if size retrieval fails, just return info and log error - if name, err := m.Filename(); err != nil { - log.Errorf("failed to obtain filename: %v", err) + if filenames, err := m.db.MsgFilenames(m.key); err != nil { + log.Errorf("failed to obtain filenames: %v", err) } else { - if info.Size, err = lib.FileSize(name); err != nil { - log.Errorf("failed to obtain file size: %v", err) - } - } - filenames, err := m.db.MsgFilenames(m.key) - if err == nil { info.Filenames = filenames + // if size retrieval fails, just return info and log error + if len(filenames) > 0 { + if info.Size, err = lib.FileSize(filenames[0]); err != nil { + log.Errorf("failed to obtain file size: %v", err) + } + } } return info, nil } -- cgit