Opened 6 years ago
Closed 5 years ago
#8297 closed defect (bug) (fixed)
The function groups_get_invites_for_user() can return inconsistent total
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 7.0.0 | Priority: | normal |
| Severity: | normal | Version: | |
| Component: | Groups | Keywords: | dev-feedback |
| Cc: |
Description (last modified by )
Now that Group invites are managed using the BP Invitations API, it looks like the total of groups can be inconsistent into this function. I've found a case where there were no groups found and the total was 1. The reason was the $wpdb . 'bp_invitations' table was containing an invite for a group that has been deleted.
Is there a reason why we don't use the total number of groups returned by the groups_get_groups() and use instead groups_get_invite_count_for_user() which run an extra DB query that can be wrong...
See https://buddypress.trac.wordpress.org/browser/trunk/src/bp-groups/bp-groups-functions.php#L1420
Change History (7)
This ticket was mentioned in Slack in #buddypress by dcavins. View the logs.
5 years ago
#6
@
5 years ago
I double-checked that invitations are removed from the invitations table when a group is deleted in the usual way, and they are, via a call to groups_delete_all_group_invites() in groups_delete_group().
Regarding the function groups_get_invites_for_user(), the groups_get_groups() call is limited to the groups that the user is invited to, found by groups_get_invited_to_group_ids(). groups_get_invite_count_for_user() is just a counting wrapper for return count( groups_get_invited_to_group_ids( $user_id ) ), so it shouldn't incur another db lookup, since the result of groups_get_invited_to_group_ids() will be cached. It seemed like a good source of truth, because groups_get_invited_to_group_ids() is the original throttle.
I agree, though, that the "total" number is going to be always accurate if it is just the groups_get_groups['total'] response, because that would only return groups that exist, excluding zombie invitations that are left over via a hasty db group delete or similar.
Thanks for opening this ticket!
Also need to double-check that invites for deleted groups are being removed when the group is deleted.