Closed (fixed)
Project:
Password Policy
Version:
8.x-3.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
14 Jan 2022 at 10:42 UTC
Updated:
26 May 2022 at 15:09 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #3
dimilias commentedComment #4
claudiu.cristeaComment #5
dimilias commented@claudiu.cristea, the direct update does not update the user. So it is a matter of whether the direct insert is an actual acceptable solution. I can provide the update you are requesting, it might still get rejected as it does not use the Drupal API in order to get the users updated.
Comment #6
andysipple commentedAdding a patch
Comment #7
eelkeblokWhile we're at it, we should also move the installation of the field into the clause that initialises the batch. The way it functions now, the process attempts to install the installation config on every iteration, which must be quite a lot of overhead too.
Comment #8
eelkeblok@idimopoulos What exactly do you mean by "the direct update does not update the user"? Do you mean caches are not invalidated? Doesn't that happen for the update process anyway?
Comment #9
dimilias commented@eelkeblok yes but not only. A direct insert in the database generally skips Drupal API. Meaning for example, user changed date is not updated (since the entity is not updated). Possible hooks are not fired, maybe rules, I don't know. I cannot predict what is not changed when we skip Drupal API. This is why I said that this might not be a suitable change.
I will do it now.
Comment #10
eelkeblokDid just that:
- Moved the import of the field into the batch initialization so it happens once.
- Added a check on the type of storage
- Changed the query to a single query per batch. Even faster 🚀
- Updated the update hook description to say it also initializes the field; sets expectations
- Removed the check for finished for the return message; it was not working (anything other than 0 for finished is truthy anyway) and it is a useful progress indicator (although with the direct query, it is hardly useful anymore; very fast even with 10s of thousands of users)
Comment #11
dimilias commentedOh sorry :) And I was wondering because I saw the MR having it already correctly :)
Ok that is fine :)
Comment #12
eelkeblokSorry about that, had not anticipated you reacting that quickly :)
You make a good point about the hooks and the like not firing. Although that might be a little tricky anyway, for a hook_update_N. Hm...
Comment #13
dimilias commentedIt is RTBC for me. If you think that initialization of the field does not need to fire everything in Drupal API (for me there is no problem not going through the API tbh) you can merge - if you have access.
Comment #14
eelkeblokI don't :)
WRT the updates not needing to run, I actually think the solution should be the other way. All we are really doing is initialising a field here; I wouldn't really want update dates to be changed for that, for example. Also, the old (which is now fallback) behaviour is actually a little dangerous, because we are in a hook_update_N, in which case we can't be sure that any modules that implement any update hooks for users have had their updates ran, and might actually break trying. This entity manipulation through the API should happen in a hook_post_update. I guess that should be spun off into a separate issue, though, this change makes it both safer and a *lot* faster for all sites that run on SQL databases (which I suppose is "most"). It should probably somehow involve moving the API-based logic to a hook_post_update and a check whether the hook_update_N was able to make the changes already.
Comment #15
eelkeblokHiding patch to avoid confusion (should still be there for those who want it). Tip: if you need a patch from a merge request, open the merge request, go to the changes and append ".diff" to the URL. You'll get the changes as a patch. Save it locally (you don't want changes to the PR to magically show up in your project at unexpected times) and apply it as any other (local) patch.
Comment #18
paulocsThank you all!