From 07de481b69a5f5d0272222833f42102ef4ac12cc Mon Sep 17 00:00:00 2001 From: Godfrain Jacques Date: Mon, 27 May 2024 10:09:15 -0700 Subject: [PATCH] fix_: fix deleted communities query (#5232) Removes the community_id IS NULL condition when fetching deleted communities and cleanup. This fixes #5222 --- protocol/communities/manager.go | 4 ---- protocol/communities/persistence.go | 13 +------------ protocol/messenger_backup.go | 9 +-------- 3 files changed, 2 insertions(+), 24 deletions(-) diff --git a/protocol/communities/manager.go b/protocol/communities/manager.go index bd8b04c75..86ba71ecc 100644 --- a/protocol/communities/manager.go +++ b/protocol/communities/manager.go @@ -889,10 +889,6 @@ func (m *Manager) JoinedAndPendingCommunitiesWithRequests() ([]*Community, error return m.persistence.JoinedAndPendingCommunitiesWithRequests(&m.identity.PublicKey) } -func (m *Manager) LeftCommunities() ([]*Community, error) { - return m.persistence.LeftCommunities(&m.identity.PublicKey) -} - func (m *Manager) DeletedCommunities() ([]*Community, error) { return m.persistence.DeletedCommunities(&m.identity.PublicKey) } diff --git a/protocol/communities/persistence.go b/protocol/communities/persistence.go index 60ac19015..0af145321 100644 --- a/protocol/communities/persistence.go +++ b/protocol/communities/persistence.go @@ -327,17 +327,6 @@ func (p *Persistence) rowsToCommunities(rows *sql.Rows) (comms []*Community, err return comms, nil } -func (p *Persistence) LeftCommunities(memberIdentity *ecdsa.PublicKey) (comms []*Community, err error) { - query := communitiesBaseQuery + ` WHERE NOT c.Joined AND NOT c.spectated AND r.state != ?` - - rows, err := p.db.Query(query, common.PubkeyToHex(memberIdentity), RequestToJoinStatePending) - if err != nil { - return nil, err - } - - return p.rowsToCommunities(rows) -} - func (p *Persistence) JoinedAndPendingCommunitiesWithRequests(memberIdentity *ecdsa.PublicKey) (comms []*Community, err error) { query := communitiesBaseQuery + ` WHERE c.Joined OR r.state = ?` @@ -350,7 +339,7 @@ func (p *Persistence) JoinedAndPendingCommunitiesWithRequests(memberIdentity *ec } func (p *Persistence) DeletedCommunities(memberIdentity *ecdsa.PublicKey) (comms []*Community, err error) { - query := communitiesBaseQuery + ` WHERE NOT c.Joined AND (r.community_id IS NULL or r.state != ?)` + query := communitiesBaseQuery + ` WHERE NOT c.Joined AND r.state != ?` rows, err := p.db.Query(query, common.PubkeyToHex(memberIdentity), RequestToJoinStatePending) if err != nil { diff --git a/protocol/messenger_backup.go b/protocol/messenger_backup.go index 14a7f7040..fed5031a5 100644 --- a/protocol/messenger_backup.go +++ b/protocol/messenger_backup.go @@ -28,7 +28,6 @@ var backupIntervalSeconds uint64 = 28800 type CommunitySet struct { Joined []*communities.Community - Left []*communities.Community Deleted []*communities.Community } @@ -298,11 +297,6 @@ func (m *Messenger) retrieveAllCommunities() (*CommunitySet, error) { return nil, err } - leftCs, err := m.communitiesManager.LeftCommunities() - if err != nil { - return nil, err - } - deletedCs, err := m.communitiesManager.DeletedCommunities() if err != nil { return nil, err @@ -310,7 +304,6 @@ func (m *Messenger) retrieveAllCommunities() (*CommunitySet, error) { return &CommunitySet{ Joined: joinedCs, - Left: leftCs, Deleted: deletedCs, }, nil } @@ -322,7 +315,7 @@ func (m *Messenger) backupCommunities(ctx context.Context, clock uint64) ([]*pro } var backupMessages []*protobuf.Backup - combinedCs := append(append(communitySet.Joined, communitySet.Left...), communitySet.Deleted...) + combinedCs := append(communitySet.Joined, communitySet.Deleted...) for _, c := range combinedCs { _, beingImported := m.importingCommunities[c.IDString()]