Skip to content

Commit

Permalink
Merge pull request #717 from basedosdados/dev
Browse files Browse the repository at this point in the history
fix: refactor contains_closed_data
  • Loading branch information
rdahis authored Nov 29, 2024
2 parents 14f54b7 + 8b0d34a commit 451be30
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 24 deletions.
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

0 comments on commit 451be30

Please sign in to comment.