Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: refactor contains_closed_data #717

Merged
merged 2 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions backend/apps/api/v1/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,8 @@ class TableAdmin(OrderedInlineModelAdminMixin, TabbedTranslationAdmin):
"number_columns",
"uncompressed_file_size",
"compressed_file_size",
"contains_open_data",
"contains_closed_data",
"page_views",
]
search_fields = [
Expand Down
33 changes: 9 additions & 24 deletions backend/apps/api/v1/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,30 +657,10 @@ def contains_open_data(self):
@property
def contains_closed_data(self):
"""Returns true if there are tables or columns with closed coverages, or if the uncompressed file size is above 1 GB"""
closed_data = False
tables = self.tables.all()
for table in tables:
# Check for closed coverages
table_coverages = table.coverages.filter(is_closed=True)
if table_coverages:
closed_data = True
break

# Check for closed columns
for column in table.columns.all():
if column.is_closed: # in the future it will be column.coverages
closed_data = True
break

# Check if uncompressed file size is between 100 MB and 1 GB
if (table.uncompressed_file_size and
table.uncompressed_file_size > 100000000 and
table.uncompressed_file_size <= 1000000000
):
closed_data = True
break

return closed_data
for table in self.tables.all():
if table.contains_closed_data:
return True
return False

@property
def contains_tables(self):
Expand Down Expand Up @@ -1052,6 +1032,11 @@ def contains_closed_data(self):
for column in self.columns.all():
if column.coverages.filter(is_closed=True).first():
return True
if (self.uncompressed_file_size and
self.uncompressed_file_size > 100 * 1024 * 1024 and
self.uncompressed_file_size <= 1000 * 1024 * 1024
):
return True
return False

@property
Expand Down
Loading