Univention Bugzilla – Bug 44898
failed import increases username counter
Last modified: 2023-06-12 15:39:47 CEST
If the import fails and the user object is not created the username counter is increased. +++ This bug was initially created as a clone of Bug #42465 +++ I started an import with --dry-run which increased ucsschoolUsernameNextNumber: 7 to ucsschoolUsernameNextNumber: 9 Which should only happen in a real import situation. In general I think this is not good to make the ldap modify call everytime but only once after the full import and increase a internal python variable instead. This makes the function UsernameHandler.format_username() also very slow and changing this could improve the performance very much! As one can see calling the function 100 times takes 10 seconds: # python -m timeit -s 'from ucsschool.importer.utils.username_handler import UsernameHandler; u = UsernameHandler(20)' -n 100 'u.format_username("foo[ALWAYSCOUNTER]")' 100 loops, best of 3: 92.2 msec per loop Also if importing of the users fails the counter gets increased.
Safety over speed. One to much raised username counter isn't such a big problem. But failing the next import, because trying to create a user twice is. Especially, as those LDAP-entries can not be managed by a normal user. Regarding speed: 0.0191 usec * 100 = 1 usec (or 1 sec incl. starting the Python interpreter). root@m90s4:~# time python -m timeit -s 'from ucsschool.importer.utils.username_handler import UsernameHandler; u = UsernameHandler(20)' -n 100 100 loops, best of 3: 0.0191 usec per loop real 0m1.535s user 0m1.348s sys 0m0.144s The test is wrong anyway, because the class is imported and an object instantiated only once per import job.