Improvement in member role sync to avoid unnecessary role remove and role reassign
If we turn on civicrm member role sync module and configure the membership to sync to a role then system removes the role and reassigns it when the sync function is invoked.
Steps to replicate:
- Create a Membership type
- Create a role in drupal
- Enable civicrm_member_roles module
- Configure the member role rule to add the new role on proper status of the membership
- Configure the membership role to sync on user login or logout
- Create a new membership for any user (note that the user now doesn't have the new role)
- Login as the user (note that the user now has the role assigned)
- Logout
If we see the code in the module it has a db_delete to delete the role assignment and then more code to reassign the role back, and these actions are performed on login or logout. This can be improved by not deleting the role and not saving the user again if there is no change required. This can be a improvement and will save few overhead on queries and on login/logout.
Thanks, Sadashiv.