Bug 49423 - reduce execution time of ou_create_post scripts
reduce execution time of ou_create_post scripts
Status: CLOSED FIXED
Product: UCS@school
Classification: Unclassified
Component: Import scripts
UCS@school 4.4
Other Linux
: P5 normal (vote)
: UCS@school 4.4 v2-errata
Assigned To: Daniel Tröder
Sönke Schwardt-Krummrich
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2019-05-07 11:35 CEST by Daniel Tröder
Modified: 2019-05-08 22:26 CEST (History)
0 users

See Also:
What kind of report is it?: Bug Report
What type of bug is this?: 2: Improvement: Would be a product improvement
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.046
Enterprise Customer affected?:
School Customer affected?:
ISV affected?:
Waiting Support:
Flags outvoted (downgraded) after PO Review:
Ticket number:
Bug group (optional):
Max CVSS v3 score:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Tröder univentionstaff 2019-05-07 11:35:00 CEST
Unify ou_create_post scripts, to reduce their execution time.
Comment 1 Daniel Tröder univentionstaff 2019-05-07 11:53:58 CEST
Six scripts have been joined into two, reducing execution time to 81%. Execution times are now logged.

[4.4] 9a54da945 Bug #49423: unify ou_create_post scripts to reduce thier execution time
[4.4] 559970d72 Bug #49423: log ou_create_post execution time
[4.4] 0d925d401 Bug #49423: advisories

ucs-school-import (17.0.6-12)
ucs-school-umc-exam (9.0.0-8)
Comment 2 Sönke Schwardt-Krummrich univentionstaff 2019-05-08 14:07:03 CEST
OK: code change
OK: functional test
OK: advisory
Comment 3 Sönke Schwardt-Krummrich univentionstaff 2019-05-08 15:36:50 CEST
Something seems to be wrong with the 70http-api_school_create part. If a OU is created via project HTTP API, the OU is not known to the import HTTP API.
Comment 4 Daniel Tröder univentionstaff 2019-05-08 17:40:02 CEST
As the hooks run as children of a Django process, they inherit its environment variables. Django locates its central settings file by evaluating the Python class path in DJANGO_SETTINGS_MODULE.

The default code for setting DJANGO_SETTINGS_MODULE is to run (in both manage.py and wsgi.py):
----
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ucsschool.http_api.app.settings")
----
This allows the caller to overwrite the project default from the command line (or application server).

In our case it lead to both ou_create_post hooks (10update_schools and 53importgroup_import_api_school_update) to load the same Django project: the one in its parents environment variable.
Thus 53importgroup_import_api_school_update (70http_api_school_create) didn't create the Django School objects in its database, but in the callers database.

[4.4] 3c19d6fab Bug #49423: unset DJANGO_SETTINGS_MODULE env before importing Django
[4.4] fae7d9416 Bug #49423: print API name
[4.4] 89cabebe9 Bug #49423: quoting
[4.4] 82c3d389a Bug #49423: execute each function in hooks
[4.4] 46c14ab84 Bug #49423: changelog
[4.4] 81f847389 Bug #49423: advisory update

ucs-school-import (17.0.6-14)
Comment 6 Sönke Schwardt-Krummrich univentionstaff 2019-05-08 21:07:54 CEST
OK: code change
OK: manual test
OK: advisory
Comment 7 Sönke Schwardt-Krummrich univentionstaff 2019-05-08 22:26:31 CEST
UCS@school 4.4 v2 has been released.

https://docs.software-univention.de/changelog-ucsschool-4.4v2-de.html

If this error occurs again, please clone this bug.