forked from Silverfish/proton-bridge
Other: Switch to faster message IDs route
The new API route lets us query exactly which message IDs a user has, allowing us to begin syncing much faster than before.
This commit is contained in:
2
go.mod
2
go.mod
@ -39,7 +39,7 @@ require (
|
|||||||
github.com/stretchr/testify v1.8.0
|
github.com/stretchr/testify v1.8.0
|
||||||
github.com/urfave/cli/v2 v2.20.3
|
github.com/urfave/cli/v2 v2.20.3
|
||||||
github.com/vmihailenco/msgpack/v5 v5.3.5
|
github.com/vmihailenco/msgpack/v5 v5.3.5
|
||||||
gitlab.protontech.ch/go/liteapi v0.38.0
|
gitlab.protontech.ch/go/liteapi v0.38.1-0.20221101102120-060b4bbab844
|
||||||
go.uber.org/goleak v1.2.0
|
go.uber.org/goleak v1.2.0
|
||||||
golang.org/x/exp v0.0.0-20221023144134-a1e5550cf13e
|
golang.org/x/exp v0.0.0-20221023144134-a1e5550cf13e
|
||||||
golang.org/x/net v0.1.0
|
golang.org/x/net v0.1.0
|
||||||
|
|||||||
4
go.sum
4
go.sum
@ -403,8 +403,8 @@ github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsr
|
|||||||
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||||
github.com/zclconf/go-cty v1.11.0 h1:726SxLdi2SDnjY+BStqB9J1hNp4+2WlzyXLuimibIe0=
|
github.com/zclconf/go-cty v1.11.0 h1:726SxLdi2SDnjY+BStqB9J1hNp4+2WlzyXLuimibIe0=
|
||||||
github.com/zclconf/go-cty v1.11.0/go.mod h1:s9IfD1LK5ccNMSWCVFCE2rJfHiZgi7JijgeWIMfhLvA=
|
github.com/zclconf/go-cty v1.11.0/go.mod h1:s9IfD1LK5ccNMSWCVFCE2rJfHiZgi7JijgeWIMfhLvA=
|
||||||
gitlab.protontech.ch/go/liteapi v0.38.0 h1:3/8HIihIxBSaLotY8D9oJS1ovCcDN15j+otSd0zO0R8=
|
gitlab.protontech.ch/go/liteapi v0.38.1-0.20221101102120-060b4bbab844 h1:HmWG1P2qhImVjx0mFMuwfBj6xmGjLzb3ZiUwe2wc8pg=
|
||||||
gitlab.protontech.ch/go/liteapi v0.38.0/go.mod h1:IM7ADWjgIL2hXopzx0WNamizEuMgM2QZl7QH12FNflk=
|
gitlab.protontech.ch/go/liteapi v0.38.1-0.20221101102120-060b4bbab844/go.mod h1:IM7ADWjgIL2hXopzx0WNamizEuMgM2QZl7QH12FNflk=
|
||||||
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
|
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
|
||||||
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
|
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
|
||||||
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
|
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
|
||||||
|
|||||||
@ -151,7 +151,7 @@ func getParentID( //nolint:funlen
|
|||||||
filter["AddressID"] = []string{authAddrID}
|
filter["AddressID"] = []string{authAddrID}
|
||||||
}
|
}
|
||||||
|
|
||||||
metadata, err := client.GetAllMessageMetadata(ctx, filter)
|
metadata, err := client.GetMessageMetadata(ctx, filter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("failed to get message metadata: %w", err)
|
return "", fmt.Errorf("failed to get message metadata: %w", err)
|
||||||
}
|
}
|
||||||
@ -176,7 +176,7 @@ func getParentID( //nolint:funlen
|
|||||||
filter["AddressID"] = []string{authAddrID}
|
filter["AddressID"] = []string{authAddrID}
|
||||||
}
|
}
|
||||||
|
|
||||||
metadata, err := client.GetAllMessageMetadata(ctx, filter)
|
metadata, err := client.GetMessageMetadata(ctx, filter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("failed to get message metadata: %w", err)
|
return "", fmt.Errorf("failed to get message metadata: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -188,19 +188,9 @@ func syncMessages( //nolint:funlen
|
|||||||
syncWorkers, syncBuffer int,
|
syncWorkers, syncBuffer int,
|
||||||
) error {
|
) error {
|
||||||
// Determine which messages to sync.
|
// Determine which messages to sync.
|
||||||
metadata, err := client.GetAllMessageMetadata(ctx, nil)
|
messageIDs, err := client.GetMessageIDs(ctx, vault.SyncStatus().LastMessageID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("get all message metadata: %w", err)
|
return fmt.Errorf("failed to get message IDs to sync: %w", err)
|
||||||
}
|
|
||||||
|
|
||||||
// Get the message IDs to sync.
|
|
||||||
messageIDs := xslices.Map(metadata, func(metadata liteapi.MessageMetadata) string {
|
|
||||||
return metadata.ID
|
|
||||||
})
|
|
||||||
|
|
||||||
// If possible, begin syncing from one beyond the last synced message.
|
|
||||||
if idx := xslices.Index(messageIDs, vault.SyncStatus().LastMessageID); idx >= 0 {
|
|
||||||
messageIDs = messageIDs[idx+1:]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch and build each message.
|
// Fetch and build each message.
|
||||||
|
|||||||
Reference in New Issue
Block a user