owner.update_owner_history - optimization

as it may be used very often
This commit is contained in:
Andrej730
2024-04-30 16:37:43 +05:00
parent 0ef683013a
commit addcf531f0
@@ -62,7 +62,8 @@ class Usecase:
self.settings = {"element": element} self.settings = {"element": element}
def execute(self) -> Union[ifcopenshell.entity_instance, None]: def execute(self) -> Union[ifcopenshell.entity_instance, None]:
if not hasattr(self.settings["element"], "OwnerHistory"): element = self.settings["element"]
if not element.is_a("IfcRoot"):
return return
user = ifcopenshell.api.owner.settings.get_user(self.file) user = ifcopenshell.api.owner.settings.get_user(self.file)
if not user: if not user:
@@ -70,14 +71,24 @@ class Usecase:
application = ifcopenshell.api.owner.settings.get_application(self.file) application = ifcopenshell.api.owner.settings.get_application(self.file)
if not application: if not application:
return return
if not self.settings["element"].OwnerHistory:
self.settings["element"].OwnerHistory = ifcopenshell.api.run("owner.create_owner_history", self.file) # 1 IfcRoot IfcOwnerHistory
return self.settings["element"].OwnerHistory owner_history = element[1]
if self.file.get_total_inverses(self.settings["element"].OwnerHistory) > 1: if not owner_history:
new = ifcopenshell.util.element.copy(self.file, self.settings["element"].OwnerHistory) owner_history = ifcopenshell.api.run("owner.create_owner_history", self.file)
self.settings["element"].OwnerHistory = new element[1] = owner_history
self.settings["element"].OwnerHistory.ChangeAction = "MODIFIED" return owner_history
self.settings["element"].OwnerHistory.LastModifiedDate = int(time.time())
self.settings["element"].OwnerHistory.LastModifyingUser = user if self.file.get_total_inverses(owner_history) > 1:
self.settings["element"].OwnerHistory.LastModifyingApplication = application owner_history = ifcopenshell.util.element.copy(self.file, owner_history)
return self.settings["element"].OwnerHistory element[1] = owner_history
# 3 IfcOwnerHistory ChangeAction
owner_history[3] = "MODIFIED"
# 4 IfcOwnerHistory LastModifiedDate
owner_history[4] = int(time.time())
# 5 IfcOwnerHistory LastModifyingUser
owner_history[5] = user
# 6 IfcOwnerHistory LastModifyingApplication
owner_history[6] = application
return owner_history