Problem/Motivation
As discussed in #2771129: "Field field_last_password_reset is unknown" while importing configuration on site without password_policy activated, it would be beneficial to move the initial processing of all user accounts into a queue in order to prevent memory time outs when there are large numbers of users needing to be updated. This issue doesn't appear when the password policy module is installed at the beginning of a site build, but if a site has thousands of users, the current process of adding the password policy setting onto each user at install is untenable.
Proposed resolution
Update the hook_install function to instead use Drupal's queue system to process necessary password updates.
Suggested alternate resolution #2983448: Refactor hook_install logic to expire passwords for existing users
Remaining tasks
- Add password policy updates into queue system.
- Add drush command to speed the processing of queued password policy updates.
- Add queue clean up to hook_uninstall.
| Comment | File | Size | Author |
|---|---|---|---|
| #18 | 2897274-install-queue-18.patch | 8.83 KB | navneet0693 |
| #4 | 2897274-install-queue-4.patch | 8.79 KB | kmoll |
Issue fork password_policy-2897274
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
joachim commentedI'd say this is critical -- it makes it impossible to install the module on a site with a large number of existing users.
Comment #3
kmoll commentedI agree it is critical. I am experiencing this on a site I am trying to update. I will create a patch and post shortly.
Comment #4
kmoll commentedHere is my first implementation of the installation queue. I've created a base class for the queue and extended it with a cron queue task. This way if someone needs to run it manually, and not on cron, it can be done. I will have a need for this. As of right now I replaced the user loop with the queuing process entirely. But I think we may want to count the number of users possibly and run the install function as it was originally written. I don't know what that number would be 1000, 5000, more less? I'm not sure, but I feel like there should be some number where we just run it on the install and some number where we queue. I'd like to hear what you guys think about that. I need to test it a bit more, but my first run through it worked. Although I don't think its complete I'm going to put this in needs review now so someone can take a look and provide some feedback on the overall implementation.
Comment #5
kmoll commentedComment #7
kmoll commentedOne thing I noticed when going through this is that it sets the users password to NOT expire. I am wondering with the default for that field set to 0, why its needed to go through and add the fields to the database. Could we not just leave the defaults, and if they are forced to reset the password, then it would go through and add the correct data to the user entity?
Comment #8
kmoll commentedComment #9
kalpaitch commentedHi, I didn't see this issue when I created #2983448: Refactor hook_install logic to expire passwords for existing users.
Despite this I still think #2983448: Refactor hook_install logic to expire passwords for existing users is a more ideal solution, there doesn't seem to be a good reason why these fields should need to be set at all on users that existed before the module was installed.
Comment #10
kalpaitch commentedComment #11
bisonbleu commentedI just ran into this issue - "Field field_last_password_reset is unknown"
Plus, on a large website with many users, I noticed that simply enabling password_policy locally takes FOREVER to complete and can lead to a WSOD. The patch in #4 fixes both of these issues (what it was intended for + the memory issue).
On the other hand, the latest patch in #2771129: "Field field_last_password_reset is unknown" while importing configuration on site without password_policy activated does not address/fix the memory issue. I've set back that RTBC issue to Needs review to get some feedback/guidance.
Comment #12
gambryHey @kalpaitch I see your point, however having all the users standardised by applying default values to the fields looks to me a better solution than storing the install_time and processing it everytime you need to query users from password_policy point of view.
It can bring technical debt - and so bugs - if we forget about it.
I feel queuing would improve performances enough to stop WSOD?
Should this be outside the foreach? The 'queue' service and the queue itself don't need to be loaded on each loop.
Same as above
Inject 'datetime.time' service and use $time->getRequestTime() instead of REQUEST_TIME.
Comment #13
gambryI've been thinking about this for a bit, and I have few questions:
If the users are - let's say - 1milion, how long will it take for the queue to clean, having 30sec (according to plugin definition) cycles? Is there any possibility for user data to be overridden if user updates his/her password_policy fields while user's queued item still needs to be processed?
Don't fields default values do the same, without all users to be processed?
Comment #14
mxh commentedIn the past, I tried to run long, batched updates via
drush updbwhich then resulted in connection timeouts (MySQL is gone) because the main Drush process did not communicate with MySQL in that time period.Comment #15
mxh commented$user_ids = \Drupal::entityTypeManager()->getStorage('user')->getQuery()->execute();This approach neither solves the problem, as the returned array can be extremely big too. A generator might help at this place, alternatively create a queue item which itself throws the next item to process into the queue.
Comment #16
navneet0693 commentedRe-rolled against latest version.
Comment #17
navneet0693 commentedComment #18
navneet0693 commentedthat was a bad patch.
Comment #19
kristen polCritical errors should be reserved for fatal errors and similar. Moving this to major.
Comment #20
kristen polGiven this issue has been quiet a few years, I'm moving it to normal priority. And it needs a reroll.
Comment #21
kristen polFixing status.
Comment #23
littlepixiez commentedI made a fork here but I believe the issue I am experiencing is slightly different - still getting an issue with
[error] InvalidArgumentException: Field field_last_password_reset is unknown. in Drupal\Core\Entity\ContentEntityBase->getTranslatedField() (line 616 of /var/www/html/web/core/lib/Drupal/Core/Entity/ContentEntityBase.php).on a fresh config import (from existing) on 4.0.x-dev.The greater issue underlying seems to be more involved, in terms of what's the best approach going forward. I would potentially say a batch process in post_update (as mentioned Comment#13), as queues may well take a long time to process?