Skip to content
Merged
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
5 changes: 4 additions & 1 deletion internal/backend/connector_updates.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,10 @@ 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 := max(runtime.NumCPU()/4, len(chunk))

// the number of routines to use for the store operations is 2* the number of CPUs or if the number of items in the chunk is less, use that number instead.
numStoreRoutines := min(len(chunk), runtime.GOMAXPROCS(0)*2)

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
Loading