Bug 44898 - failed import increases username counter
failed import increases username counter
Status: CLOSED WONTFIX
Product: UCS@school
Classification: Unclassified
Component: Import scripts
UCS@school 4.2
Other Linux
: P5 normal (vote)
: ---
Assigned To: UCS@school maintainers
:
Depends on: 42465
Blocks:
  Show dependency treegraph
 
Reported: 2017-06-29 15:35 CEST by Florian Best
Modified: 2023-06-12 15:39 CEST (History)
3 users (show)

See Also:
What kind of report is it?: Bug Report
What type of bug is this?: 3: Simply Wrong: The implementation doesn't match the docu
Who will be affected by this bug?: 2: Will only affect a few installed domains
How will those affected feel about the bug?: 2: A Pain – users won’t like this once they notice it
User Pain: 0.069
Enterprise Customer affected?:
School Customer affected?:
ISV affected?:
Waiting Support:
Flags outvoted (downgraded) after PO Review:
Ticket number:
Bug group (optional): Usability
Max CVSS v3 score:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Florian Best univentionstaff 2017-06-29 15:35:44 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.
Comment 1 Daniel Tröder univentionstaff 2017-06-29 17:38:05 CEST
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.