From 7083be429a64d8aa0de47a760cc06ecbb0a9860f Mon Sep 17 00:00:00 2001 From: Leo Hemsted Date: Fri, 10 Jun 2016 15:37:05 +0100 Subject: [PATCH 1/2] exclude notifications from job was being lazily loaded to get notification ids, so every time a job is loaded it would potentially select thousands of notifications from the database --- app/schemas.py | 1 + 1 file changed, 1 insertion(+) diff --git a/app/schemas.py b/app/schemas.py index 9c9406a15..7d20012cf 100644 --- a/app/schemas.py +++ b/app/schemas.py @@ -160,6 +160,7 @@ class JobSchema(BaseSchema): class Meta: model = models.Job + exclude = ('notifications',) class RequestVerifyCodeSchema(ma.Schema): From edc72a57ca8b8a20e13dd2f2c95afbf88eb5b9d6 Mon Sep 17 00:00:00 2001 From: Leo Hemsted Date: Fri, 10 Jun 2016 15:54:21 +0100 Subject: [PATCH 2/2] add test file for schemas --- tests/app/test_schemas.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 tests/app/test_schemas.py diff --git a/tests/app/test_schemas.py b/tests/app/test_schemas.py new file mode 100644 index 000000000..73d35002a --- /dev/null +++ b/tests/app/test_schemas.py @@ -0,0 +1,10 @@ +def test_job_schema_doesnt_return_notifications(sample_notification): + from app.schemas import job_schema + + job = sample_notification.job + assert job.notifications.count() == 1 + + data, errors = job_schema.dump(job) + + assert not errors + assert 'notifications' not in data