bito-code-review[bot] commented on PR #42393:
URL: https://github.com/apache/superset/pull/42393#issuecomment-5201093343
<!-- Bito Reply -->
The current implementation performs a database lookup for every child object
with a `uuid` to ensure the incoming `uuid` is not already owned by a different
row. To optimize this and avoid the N+1 query pattern, you can check if the
incoming `uuid` matches the `uuid` of the object currently being updated (the
`obj` variable) before performing the query. If `dict_rep['uuid'] == obj.uuid`,
the lookup is unnecessary because the object already owns the `uuid` it is
being updated with.
**superset/models/helpers.py**
```
# ... existing code ...
uuid_owner = (
db.session.query(cls).filter(cls.uuid ==
dict_rep["uuid"]).first()
)
if uuid_owner is not None and uuid_owner is not obj:
del dict_rep["uuid"]
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]