Open wmortada opened 2 years ago
@wmortada Thanks for the report - yes sync_all_wp_user_memberships()
is really old code predating my fork of the original plugin. I'd recommend running the plugin without using the WordPress pseudo-cron whether or not there are lots of WordPress Users. It's generally not that useful since the changes are largely on the CiviCRM side and synced to WordPress.
I'll leave this issue open as a cookie trail for others - along with the warning that this functionality is likely to be (a) removed or (b) rewritten.
Thanks @christianwach
Just to check, I presume that when a membership expires in CiviCRM, this won't be synced to the WordPress user until they next log in?
It should sync the moment the CiviCRM Membership status changes as a result of the cronjob. So when they log in, they will do so with their "expired" role or capabilities.
Thanks for confirming. I wasn't sure if the cron job would trigger it.
I've begun to address this in a79b23249b31ab10bb1876fdb7f3a6e2186df2d6 and will remove in future versions since it's not actually that useful.
The website in questions is running with significantly less load on the database since we switched this job off.
Good to hear @wmortada thanks for reporting back. The setting will be off by default for new installs. I have yet to decide how to handle existing ones.
We noticed some unusual database activity on a website that has this plugin installed. We believe that this was due to the
civi_wp_member_sync_refresh
job which syncs the status for every member. This code appears to loop through every user account and perform the sync. For this particular site there are more than 90,000 users so this is quite a resource intensive operation.In this particular case we decided to simply turn this job off and rely on the sync occurring when the user logs in or an admin updates the CiviCRM contact record. However, we think this code could be optimised to work for sites with a large number of users. Potentially the job could be set to run in batches.
https://github.com/christianwach/civicrm-wp-member-sync/blob/b2efc83178c2d7d6178a0facd3ab9192632939e4/includes/civi-wp-ms-members.php#L351-L380
The above function also appears to overlap with the functionality of
sync_all_civicrm_memberships
. I'm wondering if they could be combined? Particularly as the latter has the ability to process contacts in batches.https://github.com/christianwach/civicrm-wp-member-sync/blob/b2efc83178c2d7d6178a0facd3ab9192632939e4/includes/civi-wp-ms-members.php#L126