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.
This commit is contained in:
Patryk Osmaczko 2024-09-27 11:09:32 +02:00
parent 38308d48f2
commit 99e97805f8
2 changed files with 1 additions and 53 deletions

View File

@ -4120,54 +4120,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()

View File

@ -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
}