Skip to:

Opened 9 months ago

Closed 4 months ago

#8297 closed defect (bug) (fixed)

The function groups_get_invites_for_user() can return inconsistent total

Reported by: imath Owned by: dcavins
Milestone: 7.0.0 Priority: normal
Severity: normal Version:
Component: Groups Keywords: dev-feedback

Description (last modified by imath)

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...


Change History (7)

#1 @imath
9 months ago

  • Description modified (diff)

#2 @imath
9 months ago

  • Description modified (diff)

#3 @dcavins
9 months ago

  • Owner set to dcavins
  • Status changed from new to assigned

Also need to double-check that invites for deleted groups are being removed when the group is deleted.

#4 @imath
7 months ago

  • Milestone changed from Up Next to 7.0.0

This ticket was mentioned in Slack in #buddypress by dcavins. View the logs.

4 months ago

#6 @dcavins
4 months 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!

#7 @dcavins
4 months ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 12741:

Change how groups_get_invites_for_user() reports total.

In groups_get_invites_for_user() use the total returned by the groups_get_groups() call. This helps avoid the edge case where invitations to groups that no longer exist are still recorded in the invitations table. In that case, groups_get_groups() will only return existent groups.

Also update groups_get_invite_count_for_user() to use this more reliable method.

Props imath.

Fixes #8297.

Note: See TracTickets for help on using tickets.