uranusjr commented on a change in pull request #18161:
URL: https://github.com/apache/airflow/pull/18161#discussion_r724901913
##########
File path: airflow/www/views.py
##########
@@ -3414,34 +3414,56 @@ def action_mulduplicate(self, connections,
session=None):
for selected_conn in connections:
new_conn_id = selected_conn.conn_id
match = re.search(r"_copy(\d+)$", selected_conn.conn_id)
+
+ base_conn_id = selected_conn.conn_id
if match:
- conn_id_prefix = selected_conn.conn_id[: match.start()]
- new_conn_id = f"{conn_id_prefix}_copy{int(match.group(1)) + 1}"
- else:
- new_conn_id += '_copy1'
-
- dup_conn = Connection(
- new_conn_id,
- selected_conn.conn_type,
- selected_conn.description,
- selected_conn.host,
- selected_conn.login,
- selected_conn.password,
- selected_conn.schema,
- selected_conn.port,
- selected_conn.extra,
- )
+ base_conn_id = base_conn_id.split('_copy')[0]
+
+ potential_connection_ids = [f"{base_conn_id}_copy{i}" for i in
range(1, 11)]
+
+ query =
session.query(Connection.conn_id).filter(Connection.conn_id.in_(potential_connection_ids))
+
+ found_conn_id_set = {conn_id for conn_id, in query}
+
+ possible_conn_ids = []
+ for connection_id in potential_connection_ids:
+ if connection_id not in found_conn_id_set:
+ possible_conn_ids.append(connection_id)
+ possible_conn_id_iter = iter(possible_conn_ids)
Review comment:
```suggestion
possible_conn_ids = (
connection_id
for connection_id in potential_connection_ids
if connection_id not in found_conn_id_set
)
```
This would calculate the possible connection IDs lazily, i.e. if
`found_conn_id_set` is empty, only one ID would be iterated instead of
generating the whole list.
--
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]