aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHugo Osvaldo Barrera <hugo@whynothugo.nl>2024-07-06 21:58:23 +0200
committerRobin Jarry <robin@jarry.cc>2024-08-03 20:09:59 +0200
commit0ef246cf77f0ed1f8fa7f648ec2b63ebe6e99a44 (patch)
tree378910a7989e8d217c1e11ea6fb78c6ca1912260
parentc36ed72e4a594b91f477782935d55c6a1cc1025d (diff)
downloadaerc-0ef246cf77f0ed1f8fa7f648ec2b63ebe6e99a44.tar.gz
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 <hugo@whynothugo.nl> Reviewed-by: Bence Ferdinandy <bence@ferdinandy.com> Acked-by: Robin Jarry <robin@jarry.cc>
-rw-r--r--worker/notmuch/message.go17
1 files changed, 8 insertions, 9 deletions
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
}