Skip to content

Commit

Permalink
Filter out frames without versions using python, rather than the ORM
Browse files Browse the repository at this point in the history
This is much more efficient and preserves order
  • Loading branch information
Matt Daily committed Jun 3, 2024
1 parent 437312c commit da96af3
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion archive/frames/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def test_get_frame_list_exclude_empty_version_set(self):
response = self.client.get(reverse('frame-list'))
self.assertEqual(frame.version_set.count(), 0)
self.assertEqual(Frame.objects.count(), 6)
self.assertEqual(response.json()['count'], 5)
self.assertEqual(len(response.json()['results']), 5)


class TestFramePost(ReplicationTestCase):
Expand Down
1 change: 1 addition & 0 deletions archive/frames/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def list(self, request, *args, **kwargs):
page = self.paginate_queryset(queryset)
include_thumbnails = True if request.query_params.get('include_thumbnails', '').lower() == 'true' else False
json_models = [model.as_dict(include_thumbnails) for model in page]
json_models = [model for model in json_models if model['version_set']] # Filter out frames with no versions
return self.get_paginated_response(json_models)

def retrieve(self, request, *args, **kwargs):
Expand Down

0 comments on commit da96af3

Please sign in to comment.