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

Expire schemas after 7 days #5112

Merged
merged 11 commits into from
Sep 1, 2023
3 changes: 2 additions & 1 deletion redash/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ def get_schema(self, refresh=False):
logging.exception("Error sorting schema columns for data_source {}".format(self.id))
out_schema = schema
finally:
redis_connection.set(self._schema_key, json_dumps(out_schema))
ttl = int(datetime.timedelta(minutes=settings.SCHEMAS_REFRESH_SCHEDULE, days=7).total_seconds())
redis_connection.set(self._schema_key, json_dumps(out_schema), ex=ttl)

return out_schema

Expand Down
11 changes: 11 additions & 0 deletions tests/models/test_data_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@ def test_model_uses_schema_sorter(self):

self.assertEqual(out_schema, sorted_schema)

@patch("redash.redis_connection.set")
def test_expires_schema(self, mock_redis):
# default of 30min + 7 days
expected_ttl = 606600

with mock.patch("redash.query_runner.pg.PostgreSQL.get_schema") as patched_get_schema:
patched_get_schema.return_value = None
self.factory.data_source.get_schema(refresh=True)

mock_redis.assert_called_with("data_source:schema:1", "null", ex=expected_ttl)


class TestDataSourceCreate(BaseTestCase):
def test_adds_data_source_to_default_group(self):
Expand Down