Skip to content

Commit

Permalink
fix(communities)!: stop syncing community on LastOpenedAt update
Browse files Browse the repository at this point in the history
Syncing the entire community for potentially frequent actions like
`LastOpenedAt` updates is highly inefficient when using Waku as the
transport layer, as it can result in significant bandwidth overhead.
  • Loading branch information
osmaczko committed Oct 3, 2024
1 parent ae2ec8f commit 5a0e06f
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 53 deletions.
48 changes: 0 additions & 48 deletions protocol/communities_messenger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4122,54 +4122,6 @@ func (s *MessengerCommunitiesSuite) TestCommunityLastOpenedAt() {
s.Require().True(lastOpenedAt2 > lastOpenedAt1)
}

func (s *MessengerCommunitiesSuite) TestSyncCommunityLastOpenedAt() {
// Create new device
alicesOtherDevice := s.createOtherDevice(s.alice)
PairDevices(&s.Suite, alicesOtherDevice, s.alice)

// Create a community
createCommunityReq := &requests.CreateCommunity{
Membership: protobuf.CommunityPermissions_MANUAL_ACCEPT,
Name: "new community",
Color: "#000000",
Description: "new community description",
}

mr, err := s.alice.CreateCommunity(createCommunityReq, true)
s.Require().NoError(err, "s.alice.CreateCommunity")
var newCommunity *communities.Community
for _, com := range mr.Communities() {
if com.Name() == createCommunityReq.Name {
newCommunity = com
}
}
s.Require().NotNil(newCommunity)

// Mock frontend triggering communityUpdateLastOpenedAt
lastOpenedAt, err := s.alice.CommunityUpdateLastOpenedAt(newCommunity.IDString())
s.Require().NoError(err)

// Check lastOpenedAt was updated
s.Require().True(lastOpenedAt > 0)

err = tt.RetryWithBackOff(func() error {
_, err = alicesOtherDevice.RetrieveAll()
if err != nil {
return err
}
// Do we have a new synced community?
_, err := alicesOtherDevice.communitiesManager.GetSyncedRawCommunity(newCommunity.ID())
if err != nil {
return fmt.Errorf("community with sync not received %w", err)
}

return nil
})
otherDeviceCommunity, err := alicesOtherDevice.communitiesManager.GetByID(newCommunity.ID())
s.Require().NoError(err)
s.Require().True(otherDeviceCommunity.LastOpenedAt() > 0)
}

func (s *MessengerCommunitiesSuite) TestBanUserAndDeleteAllUserMessages() {
community, _ := s.createCommunity()

Expand Down
6 changes: 1 addition & 5 deletions protocol/messenger_communities.go
Original file line number Diff line number Diff line change
Expand Up @@ -934,11 +934,7 @@ func (m *Messenger) CommunityUpdateLastOpenedAt(communityID string) (int64, erro
return 0, err
}
currentTime := time.Now().Unix()
updatedCommunity, err := m.communitiesManager.CommunityUpdateLastOpenedAt(id, currentTime)
if err != nil {
return 0, err
}
err = m.syncCommunity(context.Background(), updatedCommunity, m.dispatchMessage)
_, err = m.communitiesManager.CommunityUpdateLastOpenedAt(id, currentTime)
if err != nil {
return 0, err
}
Expand Down

0 comments on commit 5a0e06f

Please sign in to comment.