From d18458767b50e886a114df3dadf7395ada4ff668 Mon Sep 17 00:00:00 2001 From: Patryk Osmaczko Date: Fri, 27 Sep 2024 11:09:32 +0200 Subject: [PATCH] fix(communities)!: stop syncing community on `LastOpenedAt` update 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. --- protocol/communities_messenger_test.go | 48 -------------------------- protocol/messenger_communities.go | 6 +--- 2 files changed, 1 insertion(+), 53 deletions(-) diff --git a/protocol/communities_messenger_test.go b/protocol/communities_messenger_test.go index 5c26f7b2ac..81e7572620 100644 --- a/protocol/communities_messenger_test.go +++ b/protocol/communities_messenger_test.go @@ -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() diff --git a/protocol/messenger_communities.go b/protocol/messenger_communities.go index 0784f7e5d6..e5c75b4515 100644 --- a/protocol/messenger_communities.go +++ b/protocol/messenger_communities.go @@ -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 }