Optimise update owner history to speed up complex operations

This commit is contained in:
Dion Moult
2021-09-20 10:17:16 +10:00
parent 2dac81ee8d
commit 90e481ce2c
7 changed files with 154 additions and 21 deletions
@@ -1,4 +1,5 @@
# Note: it is the intent for you to override these with your own functions
users = {}
def get_person(ifc):
@@ -14,3 +15,20 @@ def get_organisation(ifc):
def get_application(ifc):
applications = ifc.by_type("IfcApplication") or [None]
return applications[0]
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