Skip to content

Commit 4c48e82

Browse files
committed
Address warning about cartesian product.
1 parent 9e95836 commit 4c48e82

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

tiled/catalog/adapter.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,7 @@ async def delete(self):
888888

889889
async def delete_tree(self, external_only=True):
890890
"""
891-
Delete a Node and of the Nodes beneath it in the tree.
891+
Delete the Nodes beneath a Node in the tree.
892892
893893
That is, delete all Nodes that have this Node as an ancestor, any number
894894
of "generators" up.
@@ -902,11 +902,18 @@ async def delete_tree(self, external_only=True):
902902
if external_only:
903903
count_int_asset_statement = (
904904
select(func.count(orm.Asset.data_uri))
905-
.filter(
906-
orm.Asset.data_sources.any(
907-
orm.DataSource.management != Management.external
908-
)
905+
.select_from(orm.Asset)
906+
.join(
907+
orm.DataSourceAssetAssociation,
908+
orm.DataSourceAssetAssociation.asset_id == orm.Asset.id,
909+
)
910+
.join(
911+
orm.DataSource,
912+
orm.DataSource.id
913+
== orm.DataSourceAssetAssociation.data_source_id,
909914
)
915+
.join(orm.Node, orm.Node.id == orm.DataSource.node_id)
916+
.filter(orm.DataSource.management != Management.external)
910917
.filter(condition)
911918
)
912919
count_int_assets = (
@@ -923,6 +930,7 @@ async def delete_tree(self, external_only=True):
923930
# TODO Deal with Assets belonging to multiple DataSources.
924931
asset_ids_to_delete = (
925932
select(orm.Asset.id)
933+
.select_from(orm.Asset) # Explicitly define the starting point
926934
.join(
927935
orm.DataSourceAssetAssociation,
928936
orm.DataSourceAssetAssociation.asset_id == orm.Asset.id,

0 commit comments

Comments
 (0)