Commit 41b7ac7b authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Context component:

- Improved device_set method reducing unneeded inserts
parent 69a5d5db
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -171,7 +171,9 @@ def device_set(db_engine : Engine, request : Device) -> Tuple[Dict, bool]:
            endpoint_updates = session.execute(stmt).fetchall()
            updated_endpoints = any([(updated_at > created_at) for created_at,updated_at in endpoint_updates])

        if len(related_topologies) > 0:
        if not updated or len(related_topologies) > 1:
            # Only update topology-device relations when device is created (not updated) or when endpoints are
            # modified (len(related_topologies) > 1).
            session.execute(insert(TopologyDeviceModel).values(related_topologies).on_conflict_do_nothing(
                index_elements=[TopologyDeviceModel.topology_uuid, TopologyDeviceModel.device_uuid]
            ))