john-bodley commented on code in PR #20473:
URL: https://github.com/apache/superset/pull/20473#discussion_r904369381
##########
superset/datasets/dao.py:
##########
@@ -190,28 +185,37 @@ def update_columns(
- If there are extra columns on the metadata db that are not defined
on the List
then we delete.
"""
+
+ column_by_id = {column.id: column for column in model.columns}
new_columns = []
+
for column in property_columns:
column_id = column.get("id")
if column_id:
- column_obj = db.session.query(TableColumn).get(column_id)
- column_obj = DatasetDAO.update_column(column_obj, column,
commit=commit)
+ column_obj = DatasetDAO.update_column(
+ column_by_id.get(column_id),
+ commit=False,
+ )
else:
- column_obj = DatasetDAO.create_column(column, commit=commit)
+ column_obj = DatasetDAO.create_column(column, commit=False)
+
new_columns.append(column_obj)
+
# Checks if an exiting column is missing from properties and delete it
+ column_ids = {column.id for column in new_columns}
+
for existing_column in model.columns:
- if existing_column.id not in [column.id for column in new_columns]:
Review Comment:
Optimized looping.
--
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]