Optimise create owner history to not rely on a person and organisation lookup, speeding up long procedures

This commit is contained in:
Dion Moult
2021-10-01 11:05:35 +10:00
parent 8bcec29429
commit 0a27308532
11 changed files with 92 additions and 107 deletions
@@ -1,15 +1,4 @@
# Note: it is the intent for you to override these with your own functions
users = {}
def get_person(ifc):
people = ifc.by_type("IfcPerson") or [None]
return people[0]
def get_organisation(ifc):
organisations = ifc.by_type("IfcOrganization") or [None]
return organisations[0]
def get_application(ifc):
@@ -18,17 +7,5 @@ def get_application(ifc):
def get_user(ifc):
person = get_person(ifc)
organisation = get_organisation(ifc)
if not person or not organisation:
return
key = f"{person.id()}-{organisation.id()}"
user = users.get(key)
if not user:
for element in ifc.by_type("IfcPersonAndOrganization"):
if element.ThePerson == person and element.TheOrganization == organisation:
users[key] = element
user = element
if not user:
return ifc.create_entity("IfcPersonAndOrganization", ThePerson=person, TheOrganization=organisation)
return user
users = ifc.by_type("IfcPersonAndOrganization") or [None]
return users[0]