Skip to content

Commit

Permalink
Another follow-up to #930
Browse files Browse the repository at this point in the history
  • Loading branch information
Marina Samuel committed Apr 4, 2019
1 parent 5d03b54 commit 1dff4c4
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions redash/tasks/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,7 @@ def get_table_sample_data(existing_columns, data_source_id, table_name, table_id
column_examples = []
for persisted_column in persisted_columns:
column_example = sample.get(persisted_column.name, None)
column_example = column_example if isinstance(column_example, unicode) else (
str(column_example).decode("utf-8", errors="replace").strip()
)
column_example = column_example if isinstance(column_example, unicode) else str(column_example)
column_example = truncate_long_string(column_example, 4000)

column_examples.append({
Expand All @@ -274,19 +272,13 @@ def get_table_sample_data(existing_columns, data_source_id, table_name, table_id


def cleanup_data_in_table(table_model):
removed_metadata = table_model.query.filter(
table_model.exists.is_(False),
).options(load_only('updated_at'))

for removed_metadata_row in removed_metadata:
is_old_data = (
utils.utcnow() - removed_metadata_row.updated_at
) > datetime.timedelta(days=settings.SCHEMA_METADATA_TTL_DAYS)

if is_old_data:
table_model.query.filter(
table_model.id == removed_metadata_row.id,
).delete()
TTL_DAYS_AGO = (
utils.utcnow() - datetime.timedelta(days=settings.SCHEMA_METADATA_TTL_DAYS))

table_model.query.filter(
table_model.exists == False,
table_model.updated_at < TTL_DAYS_AGO
).delete()

db.session.commit()

Expand Down

0 comments on commit 1dff4c4

Please sign in to comment.