Every time a user is loaded, ldapdata_user_profile_load takes the data that was just loaded from ldap, and saves it to the user profile. This procedure requires one write query per field. If for example you are mapping 6 fields, and you load 12 user objects on a page, this results in 72 write queries on a page. Ouch! This is a serious performance impact for even small sites.
This function also does not use the user API to save the data. I'm assuming that's because we may be dealing with fields that the current user may or may not have access privelages for?
I think there's two possible routes to ease the situation:
1) Only update Drupal if the value is different. Seems straightforward, I'll investigate.
2) In most installations having up-to-the-minute synchronization is probably not necessary. It may be an idea to move this functionality to cron. Syncronize n users per cron run.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | ldapdata.module.patch | 495 bytes | gurubert |
| #1 | ldap_integration_sync_on_update.diff | 1.62 KB | dalin |
Comments
Comment #1
dalinHere's a patch that only writes to the profile the fields that have changed (if any).
Comment #2
gurubert commentedHi,
I just made a patch that also reduces the number of queries to LDAP and the database.
I introduced a static variable loaded in _ldapdata_user_load() that checks if a user has already been loaded.
Is it really necessary to query LDAP every time hook_user("load", ...) is called for one page?
I assume that there are other places in the ldap_integration code where this type of optimization could be applied.
Comment #3
wvd_vegt commentedHi,
Can your patch work correctly if users are never removed from the static array?
I would think you better can check if the $profile_fields (see ldapdata_admin_edit()) in the $user object are present at all.
So basically cache $profile_fields = _ldapdata_retrieve_profile_fields() in a static array instead and use it to see if the user has fields originating from ldap at all.
Comment #4
gurubert commentedHi,
why should user data change over the short time the page is generated?
After the page has been generated the PHP script is finished and all the static variables are discarded.
Static PHP variables are not persistent between page requests.
Comment #5
wvd_vegt commentedHi,
In that case it should work.
My approach in another (ldap related) module was to remove all the equal fields from an array and only save those left (if any).
Comment #6
eriktoyra commentedSubscribing to this issue.
Comment #7
eriktoyra commentedCould this be something that we could implement for the 5.x-1.3 version to speed up the performance? http://drupal.org/node/376984
Comment #8
johnbarclay commentedClosing 5.x issues to clean out issue queue.