mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-20 09:06:45 +00:00
fix(GODT-2829): Sync Service fixes
Fix tracking of child jobs. The build stage splits the incoming work even further, but this was not reflected in the wait group counter. This also fixes an issue where the cache was cleared to late. Add more debug info for analysis. Refactor sync state interface in order to have persistent sync rate.
This commit is contained in:
@ -24,6 +24,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/ProtonMail/gluon/async"
|
||||
"github.com/ProtonMail/go-proton-api"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@ -54,6 +55,9 @@ type Job struct {
|
||||
|
||||
panicHandler async.PanicHandler
|
||||
downloadCache *DownloadCache
|
||||
|
||||
metadataFetched int64
|
||||
totalMessageCount int64
|
||||
}
|
||||
|
||||
func NewJob(ctx context.Context,
|
||||
@ -178,6 +182,36 @@ func (s *childJob) userID() string {
|
||||
return s.job.userID
|
||||
}
|
||||
|
||||
func (s *childJob) chunkDivide(chunks [][]proton.FullMessage) []childJob {
|
||||
numChunks := len(chunks)
|
||||
|
||||
if numChunks == 1 {
|
||||
return []childJob{*s}
|
||||
}
|
||||
|
||||
result := make([]childJob, numChunks)
|
||||
for i := 0; i < numChunks-1; i++ {
|
||||
result[i] = s.job.newChildJob(chunks[i][len(chunks[i])-1].ID, int64(len(chunks[i])))
|
||||
collectIDs(&result[i], chunks[i])
|
||||
}
|
||||
|
||||
result[numChunks-1] = *s
|
||||
collectIDs(&result[numChunks-1], chunks[numChunks-1])
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func collectIDs(j *childJob, msgs []proton.FullMessage) {
|
||||
j.cachedAttachmentIDs = make([]string, 0, len(msgs))
|
||||
j.cachedMessageIDs = make([]string, 0, len(msgs))
|
||||
for _, msg := range msgs {
|
||||
j.cachedMessageIDs = append(j.cachedMessageIDs, msg.ID)
|
||||
for _, attach := range msg.Attachments {
|
||||
j.cachedAttachmentIDs = append(j.cachedAttachmentIDs, attach.ID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *childJob) onFinished(ctx context.Context) {
|
||||
s.job.log.Infof("Child job finished")
|
||||
s.job.onJobFinished(ctx, s.lastMessageID, s.messageCount)
|
||||
|
||||
Reference in New Issue
Block a user