@@ -351,7 +351,7 @@ def check_channel_space(self, channel):
351351 tree_cte = With (self .get_user_active_trees ().distinct (), name = "trees" )
352352
353353 user_files_cte = With (
354- self .files .get_queryset ().only (
354+ self .files .get_queryset ().values (
355355 "id" ,
356356 "checksum" ,
357357 "contentnode_id" ,
@@ -369,7 +369,7 @@ def check_channel_space(self, channel):
369369 .filter (
370370 Exists (
371371 tree_cte .join (
372- ContentNode .objects .only ( "id" , "tree_id" ),
372+ ContentNode .objects .all ( ),
373373 tree_id = tree_cte .col .tree_id ,
374374 )
375375 .with_cte (tree_cte )
@@ -378,10 +378,8 @@ def check_channel_space(self, channel):
378378 )
379379 )
380380
381- editable_files_qs = self ._filter_storage_billable_files (editable_files_qs )
382-
383381 existing_checksums_cte = With (
384- editable_files_qs .values ("checksum" , "file_format_id" ).distinct (),
382+ editable_files_qs .values ("checksum" ).distinct (),
385383 name = "existing_checksums" ,
386384 )
387385
@@ -390,36 +388,35 @@ def check_channel_space(self, channel):
390388 .with_cte (user_files_cte )
391389 .filter (
392390 Exists (
393- ContentNode .objects .only ( "id" ). filter (
391+ ContentNode .objects .filter (
394392 tree_id = channel .staging_tree .tree_id ,
395393 id = OuterRef ("contentnode_id" ),
396394 )
397395 )
398396 )
399397 )
400398
401- staging_files_qs = self ._filter_storage_billable_files (staging_files_qs )
402-
403- staging_files_qs = (
399+ new_staging_files_qs = (
404400 staging_files_qs .with_cte (tree_cte )
405401 .with_cte (existing_checksums_cte )
406402 .exclude (
407403 Exists (
408404 existing_checksums_cte .queryset ().filter (
409405 checksum = OuterRef ("checksum" ),
410- file_format_id = OuterRef ("file_format_id" ),
411406 )
412407 )
413408 )
414409 )
415410
411+ new_staging_files_qs = self ._filter_storage_billable_files (new_staging_files_qs )
412+
416413 unique_staging_ids = (
417- staging_files_qs .order_by ("checksum" , "id" )
414+ new_staging_files_qs .order_by ("checksum" , "id" )
418415 .distinct ("checksum" )
419416 .values ("id" )
420417 )
421418 staged_size = float (
422- staging_files_qs .filter (id__in = Subquery (unique_staging_ids )).aggregate (
419+ new_staging_files_qs .filter (id__in = Subquery (unique_staging_ids )).aggregate (
423420 used = Sum ("file_size" )
424421 )["used" ]
425422 or 0
0 commit comments