aboutsummaryrefslogtreecommitdiffstats
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
parent9cc507049b7b4b1c5d431deaec0854f4bec67dba (diff)
downloadaerc-a5648c3c0468a27e722159a115a4260c5e84c465.tar.gz
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>
-rw-r--r--go.mod1
-rw-r--r--go.sum2
-rw-r--r--worker/mbox/worker.go20
3 files changed, 11 insertions, 12 deletions
diff --git a/go.mod b/go.mod
index a429c283..9b712a34 100644
--- a/go.mod
+++ b/go.mod
@@ -27,7 +27,6 @@ require (
github.com/lithammer/fuzzysearch v1.1.5
github.com/mattn/go-isatty v0.0.18
github.com/mattn/go-runewidth v0.0.14
- github.com/miolini/datacounter v1.0.3
github.com/pkg/errors v0.9.1
github.com/rivo/uniseg v0.4.4
github.com/riywo/loginshell v0.0.0-20200815045211-7d26008be1ab
diff --git a/go.sum b/go.sum
index 6693deba..6b207f28 100644
--- a/go.sum
+++ b/go.sum
@@ -110,8 +110,6 @@ github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m
github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU=
github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
-github.com/miolini/datacounter v1.0.3 h1:tanOZPVblGXQl7/bSZWoEM8l4KK83q24qwQLMrO/HOA=
-github.com/miolini/datacounter v1.0.3/go.mod h1:C45dc2hBumHjDpEU64IqPwR6TDyPVpzOqqRTN7zmBUA=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
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
}