Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions async/panic_handler.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package async

type PanicHandler interface {
HandlePanic(interface{})
HandlePanic(any)
}

type NoopPanicHandler struct{}

func (n NoopPanicHandler) HandlePanic(r interface{}) {}
func (n NoopPanicHandler) HandlePanic(r any) {}

func HandlePanic(panicHandler PanicHandler) {
if panicHandler == nil {
Expand Down
2 changes: 1 addition & 1 deletion async/panic_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

type recoverHandler struct{}

func (h recoverHandler) HandlePanic(r interface{}) {
func (h recoverHandler) HandlePanic(r any) {
fmt.Println("recoverHandler", r)
}

Expand Down
2 changes: 1 addition & 1 deletion benchmarks/gluon_bench/benchmark/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func RunMain() {

benchmarkStats := make([]*reporter.BenchmarkStatistics, 0, numRuns)

for r := uint(0); r < numRuns; r++ {
for r := range numRuns {
if *flags.Verbose {
fmt.Printf("Benchmark Run: %v\n", r)
}
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/gluon_bench/imap_benchmarks/build_mailbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func BuildMailbox(cl *client.Client, mailbox string, messageCount int) error {
func BuildMailboxWithMessages(cl *client.Client, mailbox string, messageCount int, messages []string) error {
messagesLen := len(messages)

for i := 0; i < messageCount; i++ {
for i := range messageCount {
literal := fmt.Sprintf("To: %v@a.com\r\nFrom: %v@a.com\r\n", uuid.NewString(), uuid.NewString()) + messages[i%messagesLen]
if err := AppendToMailbox(cl, mailbox, literal, time.Now()); err != nil {
return err
Expand Down
6 changes: 3 additions & 3 deletions benchmarks/gluon_bench/imap_benchmarks/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ func FetchMessage(cl *client.Client, sequenceSet *imap.SeqSet, items ...imap.Fet
return cl.Fetch(sequenceSet, items, ch)
}

func flagsToInterface(flags ...string) []interface{} {
return xslices.Map(flags, func(f string) interface{} {
return interface{}(f)
func flagsToInterface(flags ...string) []any {
return xslices.Map(flags, func(f string) any {
return any(f)
})
}

Expand Down
24 changes: 10 additions & 14 deletions benchmarks/gluon_bench/imap_benchmarks/parallel_seqset.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func NewParallelSeqSetFromFile(path string, numWorkers uint) (*ParallelSeqSet, e
}

seqSets := make([][]*imap.SeqSet, numWorkers)
for i := uint(0); i < numWorkers; i++ {
for i := range numWorkers {
seqSets[i] = list
}

Expand All @@ -43,11 +43,11 @@ func NewParallelSeqSetExpunge(count uint32, numWorkers uint, generateIntervals,
workerSplit := count / uint32(numWorkers)
available := make([]uint32, count)

for r := uint32(0); r < count; r++ {
for r := range count {
available[r] = r + 1
}

for i := uint(0); i < numWorkers; i++ {
for i := range numWorkers {
available := available[(uint32(i) * workerSplit):(uint32(i+1) * workerSplit)]
list := make([]*imap.SeqSet, 0, workerSplit)

Expand Down Expand Up @@ -80,7 +80,7 @@ func NewParallelSeqSetExpunge(count uint32, numWorkers uint, generateIntervals,
}
} else {
count := uint32(len(available))
for r := uint32(0); r < count; r++ {
for r := range count {
index := rand.Uint32() % (count - r)
seqSet := &imap.SeqSet{}
if uid {
Expand All @@ -106,12 +106,12 @@ func NewParallelSeqSetExpunge(count uint32, numWorkers uint, generateIntervals,
func NewParallelSeqSetRandom(count uint32, numWorkers uint, generateIntervals, randomDrain, uid bool) *ParallelSeqSet {
lists := make([][]*imap.SeqSet, numWorkers)

for i := uint(0); i < numWorkers; i++ {
for i := range numWorkers {
list := make([]*imap.SeqSet, 0, count)

if randomDrain {
available := make([]uint32, count)
for r := uint32(0); r < count; r++ {
for r := range count {
available[r] = r + 1
}

Expand All @@ -134,11 +134,7 @@ func NewParallelSeqSetRandom(count uint32, numWorkers uint, generateIntervals, r
if uid {
seqSet.AddRange(available[index], available[index+intervalRange-1])
} else {
endSeq := index + intervalRange + 1

if endSeq > itemsLeft {
endSeq = itemsLeft
}
endSeq := min(index+intervalRange+1, itemsLeft)

seqSet.AddRange(index+1, endSeq)
}
Expand All @@ -153,7 +149,7 @@ func NewParallelSeqSetRandom(count uint32, numWorkers uint, generateIntervals, r
available = append(available[:cutIndex], available[index+intervalRange:]...)
}
} else {
for r := uint32(0); r < count; r++ {
for r := range count {
index := rand.Uint32() % (count - r)
seqSet := &imap.SeqSet{}
if uid {
Expand All @@ -167,7 +163,7 @@ func NewParallelSeqSetRandom(count uint32, numWorkers uint, generateIntervals, r
}
}
} else {
for r := uint32(0); r < count; r++ {
for range count {
var seqSet *imap.SeqSet
if !generateIntervals {
seqSet = RandomSequenceSetNum(count)
Expand All @@ -188,7 +184,7 @@ func NewParallelSeqSetRandom(count uint32, numWorkers uint, generateIntervals, r
// NewParallelSeqSetAll generates once sequence set for each worker which covers everything (1:*).
func NewParallelSeqSetAll(numWorkers uint) *ParallelSeqSet {
lists := make([][]*imap.SeqSet, numWorkers)
for i := uint(0); i < numWorkers; i++ {
for i := range numWorkers {
lists[i] = []*imap.SeqSet{NewSequenceSetAll()}
}

Expand Down
14 changes: 7 additions & 7 deletions benchmarks/gluon_bench/imap_benchmarks/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ func (s *SearchTextQuery) Run(ctx context.Context, cl *client.Client, workerInde

fieldsStr := []string{"TEXT", s.queries[keywordIndex]}

fields := xslices.Map(fieldsStr, func(v string) interface{} {
return interface{}(v)
fields := xslices.Map(fieldsStr, func(v string) any {
return any(v)
})

if err := criteria.ParseWithCharset(fields, nil); err != nil {
Expand Down Expand Up @@ -162,7 +162,7 @@ func (s *SearchSinceQuery) Setup(ctx context.Context, cl *client.Client, searchC
} else {
s.dates = make([]string, 0, searchCount)

for i := uint32(0); i < searchCount; i++ {
for range searchCount {
t := time.Date(1980+rand.Intn(40), time.Month(rand.Intn(12)), rand.Intn(28), 0, 0, 0, 0, time.UTC)
s.dates = append(s.dates, t.Format("02-Jan-2006"))
}
Expand All @@ -181,8 +181,8 @@ func (s *SearchSinceQuery) Run(ctx context.Context, cl *client.Client, workerInd

fieldsStr := []string{"SINCE", d}

fields := xslices.Map(fieldsStr, func(v string) interface{} {
return interface{}(v)
fields := xslices.Map(fieldsStr, func(v string) any {
return any(v)
})

if err := criteria.ParseWithCharset(fields, nil); err != nil {
Expand Down Expand Up @@ -215,8 +215,8 @@ func (s *SearchCmdQuery) Setup(ctx context.Context, cl *client.Client, searchCou

queries := strings.Split(*searchCmdQueryFlag, " ")

fields := xslices.Map(queries, func(v string) interface{} {
return interface{}(v)
fields := xslices.Map(queries, func(v string) any {
return any(v)
})

if err := s.criteria.ParseWithCharset(fields, nil); err != nil {
Expand Down
6 changes: 2 additions & 4 deletions benchmarks/gluon_bench/reporter/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package reporter
import (
"fmt"
"math"
"sort"
"slices"
"strings"
"time"

Expand Down Expand Up @@ -39,9 +39,7 @@ func (b *BenchmarkStatistics) String() string {

func NewBenchmarkStatistics(extra BenchmarkExtra, durations ...time.Duration) *BenchmarkStatistics {
sortedDurations := durations
sort.Slice(sortedDurations, func(i1, i2 int) bool {
return sortedDurations[i1] < sortedDurations[i2]
})
slices.Sort(sortedDurations)

statistics := &BenchmarkStatistics{
Extra: extra,
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/gluon_bench/store_benchmarks/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (g *Get) Run(ctx context.Context, st store.Store) (*reporter.BenchmarkRun,
uuidLen := len(g.uuids)

return RunStoreWorkers(ctx, st, func(ctx context.Context, s store.Store, dc *timing.Collector, u uint) error {
for i := 0; i < uuidLen; i++ {
for range uuidLen {
index := rand.Intn(uuidLen)

dc.Start()
Expand Down
7 changes: 2 additions & 5 deletions benchmarks/gluon_bench/store_benchmarks/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func CreateRandomState(st store.Store, count uint) ([]imap.InternalMessageID, er
uuids := make([]imap.InternalMessageID, 0, count)
data := make([]byte, *flags.StoreItemSize)

for i := uint(0); i < count; i++ {
for range count {
uuid := imap.NewInternalMessageID()

if err := st.Set(uuid, bytes.NewReader(data)); err != nil {
Expand Down Expand Up @@ -65,10 +65,7 @@ func RunStoreWorkersSplitRange(ctx context.Context, st store.Store, length uint,
workDivision := length / *flags.StoreWorkers

return RunStoreWorkers(ctx, st, func(ctx context.Context, s store.Store, collector *timing.Collector, u uint) error {
end := workDivision * (u + 1)
if end > length {
end = length
}
end := min(workDivision*(u+1), length)

return fn(ctx, st, collector, u*workDivision, end)
})
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/gluon_bench/utils/cmd_profiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (c *DurationCmdProfiler) Stop(cmdType int) {

func NewDurationCmdProfiler() *DurationCmdProfiler {
profiler := &DurationCmdProfiler{}
for i := 0; i < len(profiler.durations); i++ {
for i := range len(profiler.durations) {
profiler.durations[i] = make([]time.Duration, 0, 128)
}

Expand Down Expand Up @@ -59,7 +59,7 @@ func (c *DurationCmdProfilerBuilder) Merge() [profiling.CmdTypeTotal][]time.Dura
var result [profiling.CmdTypeTotal][]time.Duration

for _, v := range c.profilers {
for i := 0; i < len(result); i++ {
for i := range len(result) {
result[i] = append(result[i], v.durations[i]...)
}
}
Expand Down
2 changes: 1 addition & 1 deletion connector/dummy_simulate.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (conn *Dummy) MessagesCreated(messages []imap.Message, literals [][]byte, m

var updates []*imap.MessageCreated

for i := 0; i < len(messages); i++ {
for i := range messages {
parsedMessage, err := imap.NewParsedMessage(literals[i])
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion imap/command/authenticate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestParser_Authenticate(t *testing.T) {
var continued bool

tag := fmt.Sprintf("A%04d", i)
authString := base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("\x00%s\x00%s", data.UserID, data.Password)))
authString := base64.StdEncoding.EncodeToString(fmt.Appendf(nil, "\x00%s\x00%s", data.UserID, data.Password))
input := toIMAPLine(tag+` AUTHENTICATE PLAIN`, authString)
s := rfcparser.NewScanner(bytes.NewReader(input))
p := NewParser(s, WithLiteralContinuationCallback(continuationChecker(&continued)))
Expand Down
2 changes: 1 addition & 1 deletion imap/command/date_time.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ var dateMonthToInt = map[string]time.Month{
func ParseDateMonth(p *rfcparser.Parser) (time.Month, error) {
month := make([]byte, 3)

for i := 0; i < 3; i++ {
for i := range 3 {
if err := p.Consume(rfcparser.TokenTypeChar, "unexpected character for date month"); err != nil {
return 0, err
}
Expand Down
1 change: 0 additions & 1 deletion imap/seqset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ func TestSeqSet(t *testing.T) {
}

for _, tc := range tests {
tc := tc

t.Run(tc.want, func(t *testing.T) {
assert.Equal(t, tc.want, NewSeqSet(tc.have).String())
Expand Down
6 changes: 3 additions & 3 deletions imap/uid_validity_generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestEpochUIDValidityGenerator_Generate(t *testing.T) {

var uids = make([]UID, UIDCount)

for i := 0; i < UIDCount; i++ {
for i := range UIDCount {
uid, err := generator.Generate()
require.NoError(t, err)

Expand All @@ -29,7 +29,7 @@ func TestEpochUIDValidityGenerator_Generate(t *testing.T) {
uid, err := generator.Generate()
require.NoError(t, err)

for i := 0; i < UIDCount-1; i++ {
for i := range UIDCount - 1 {
assert.Less(t, uids[i], uids[i+1])
}

Expand All @@ -51,7 +51,7 @@ func TestEpochUIDValidityGenerator_GenerateParallel(t *testing.T) {

slices.Sort(uids)

for i := 0; i < UIDCount-1; i++ {
for i := range UIDCount - 1 {
assert.Less(t, uids[i], uids[i+1])
}
}
5 changes: 1 addition & 4 deletions internal/backend/connector_updates.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,7 @@ func (user *user) applyMessagesCreated(ctx context.Context, update *imap.Message

for _, chunk := range xslices.Chunk(messagesToCreate, db.ChunkLimit) {
// Create messages in the store in parallel
numStoreRoutines := runtime.NumCPU() / 4
if numStoreRoutines < len(chunk) {
Comment thread
ElectroNafta marked this conversation as resolved.
numStoreRoutines = len(chunk)
}
numStoreRoutines := max(runtime.NumCPU()/4, len(chunk))
if err := parallel.DoContext(ctx, numStoreRoutines, len(chunk), func(ctx context.Context, i int) error {
msg := chunk[i]
if err := user.store.SetUnchecked(msg.InternalID, msg.reader); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/session/cmdwatcher/watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (m *mockFeatureFlagProvider) SetFlag(key string, value bool) {

type mockPanicHandler struct{}

func (m *mockPanicHandler) HandlePanic(r interface{}) {}
func (m *mockPanicHandler) HandlePanic(r any) {}

func createTestService(testInterval time.Duration, featureFlags map[string]bool) (*cmdwatcher.Service, *mockProgressSender) {
ctx := context.Background()
Expand Down
9 changes: 2 additions & 7 deletions internal/state/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package state

import (
"fmt"
"slices"

"github.com/ProtonMail/gluon/imap"
)
Expand Down Expand Up @@ -83,11 +84,5 @@ func (f *AnyMessageIDStateFilter) Filter(s *State) bool {
return false
}

for _, msgID := range f.MessageIDs {
if s.snap.hasMessage(msgID) {
return true
}
}

return false
return slices.ContainsFunc(f.MessageIDs, s.snap.hasMessage)
}
4 changes: 2 additions & 2 deletions internal/state/mailbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ func (m *Mailbox) Copy(ctx context.Context, seq []command.SeqRange, name string)
msgIDs := make([]db.MessageIDPair, len(messages))
msgUIDs := make([]imap.UID, len(messages))

for i := 0; i < len(messages); i++ {
for i := range messages {
snapMsg := messages[i]
msgUIDs[i] = snapMsg.UID
msgIDs[i] = snapMsg.ID
Expand Down Expand Up @@ -351,7 +351,7 @@ func (m *Mailbox) Move(ctx context.Context, seq []command.SeqRange, name string)
msgIDs := make([]db.MessageIDPair, len(messages))
msgUIDs := make([]imap.UID, len(messages))

for i := 0; i < len(messages); i++ {
for i := range messages {
snapMsg := messages[i]
msgUIDs[i] = snapMsg.UID
msgIDs[i] = snapMsg.ID
Expand Down
9 changes: 3 additions & 6 deletions internal/state/mailbox_fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,9 @@ func (m *Mailbox) Fetch(ctx context.Context, cmd *command.Fetch, ch chan respons
if !contexts.IsParallelismDisabledCtx(ctx) && (len(snapMessages) > minCountForParallelism || (len(snapMessages) > 1 && needsLiteral)) {
// If multiple fetch request are happening in parallel, reduce the number of goroutines in proportion to that
// to avoid overloading the user's machine.
parallelism = runtime.NumCPU() / int(activeFetchRequests)

// make sure that if division hits 0, we run single threaded rather than use MAXGOPROCS
if parallelism < 1 {
parallelism = 1
}
parallelism = max(
// make sure that if division hits 0, we run single threaded rather than use MAXGOPROCS
runtime.NumCPU()/int(activeFetchRequests), 1)
} else {
parallelism = 1
}
Expand Down
1 change: 0 additions & 1 deletion internal/state/match_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ func TestMatch(t *testing.T) {
}

for _, tt := range tests {
tt := tt

t.Run(fmt.Sprintf("%#v", tt), func(t *testing.T) {
res, match := match(tt.ref, tt.pattern, tt.delimiter, tt.name)
Expand Down
Loading
Loading