aboutsummaryrefslogtreecommitdiff
path: root/worker
diff options
context:
space:
mode:
authorTim Culverhouse <tim@timculverhouse.com>2023-08-30 15:41:29 -0500
committerRobin Jarry <robin@jarry.cc>2023-08-31 00:05:31 +0200
commita5648c3c0468a27e722159a115a4260c5e84c465 (patch)
tree5b89e875c1ecf8f741c7a60291ebf76af7c9d3c4 /worker
parent9cc507049b7b4b1c5d431deaec0854f4bec67dba (diff)
downloadaerc-a5648c3c0468a27e722159a115a4260c5e84c465.tar.gz
aerc-a5648c3c0468a27e722159a115a4260c5e84c465.zip
mbox: remove datacounter dependency for size info
The mbox worker uses the only reference to the datacounter object (see previous commit where it was removed from 'postpone'). The counter object in mbox is counting the size of the mbox message. Use io.Discard and the result from the io.Copy call to set this size. This saves us from writing to memory, since io.Discard will not store any of the written bytes. It also removes the dependency on datacounter. Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'worker')
-rw-r--r--worker/mbox/worker.go20
1 files changed, 11 insertions, 9 deletions
diff --git a/worker/mbox/worker.go b/worker/mbox/worker.go
index 8ed04e05..eb622e93 100644
--- a/worker/mbox/worker.go
+++ b/worker/mbox/worker.go
@@ -15,7 +15,6 @@ import (
"git.sr.ht/~rjarry/aerc/worker/handlers"
"git.sr.ht/~rjarry/aerc/worker/lib"
"git.sr.ht/~rjarry/aerc/worker/types"
- "github.com/miolini/datacounter"
)
func init() {
@@ -454,14 +453,17 @@ func messageInfo(m lib.RawMessage, needSize bool) (*models.MessageInfo, error) {
if err != nil {
return nil, err
}
- if needSize {
- if r, err := m.NewReader(); err == nil {
- var buf bytes.Buffer
- ctr := datacounter.NewWriterCounter(&buf)
- if _, err := io.Copy(ctr, r); err == nil {
- info.Size = uint32(ctr.Count())
- }
- }
+ if !needSize {
+ return info, nil
+ }
+ r, err := m.NewReader()
+ if err != nil {
+ return nil, err
+ }
+ size, err := io.Copy(io.Discard, r)
+ if err != nil {
+ return nil, err
}
+ info.Size = uint32(size)
return info, nil
}