Skip to content
This repository has been archived by the owner on Dec 7, 2022. It is now read-only.
/ pulp Public archive

Commit

Permalink
Fix performance regression in associated unit queries.
Browse files Browse the repository at this point in the history
The mongoengine object instantiation is too slow.
closes #1702
  • Loading branch information
jortel committed Feb 22, 2016
1 parent 3d698a6 commit 3fbb132
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions server/pulp/server/controllers/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ def get_associated_unit_ids(repo_id, unit_type, repo_content_unit_q=None):
qs = model.RepositoryContentUnit.objects(q_obj=repo_content_unit_q,
repo_id=repo_id,
unit_type_id=unit_type)
for assoc in qs.only('unit_id'):
yield assoc.unit_id
for assoc in qs.only('unit_id').as_pymongo():
yield assoc['unit_id']


def get_unit_model_querysets(repo_id, model_class, repo_content_unit_q=None):
Expand Down
10 changes: 5 additions & 5 deletions server/test/unit/server/controllers/test_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,26 @@ class DemoModel(model.ContentUnit):
class TestGetAssociatedUnitIDs(unittest.TestCase):
def setUp(self):
self.associations = [
model.RepositoryContentUnit(repo_id='repo1', unit_id='a', unit_type_id='demo_model'),
model.RepositoryContentUnit(repo_id='repo1', unit_id='b', unit_type_id='demo_model'),
dict(repo_id='repo1', unit_id='a', unit_type_id='demo_model'),
dict(repo_id='repo1', unit_id='b', unit_type_id='demo_model'),
]

def test_returns_ids(self, mock_objects):
mock_objects.return_value.only.return_value = self.associations
mock_objects.return_value.only.return_value.as_pymongo.return_value = self.associations

ret = list(repo_controller.get_associated_unit_ids('repo1', 'demo_model'))

self.assertEqual(ret, ['a', 'b'])

def test_returns_generator(self, mock_objects):
mock_objects.return_value.only.return_value = self.associations
mock_objects.return_value.only.return_value.as_pymongo.return_value = self.associations

ret = repo_controller.get_associated_unit_ids('repo1', 'demo_model')

self.assertTrue(inspect.isgenerator(ret))

def test_uses_q(self, mock_objects):
mock_objects.return_value.only.return_value = self.associations
mock_objects.return_value.only.return_value.as_pymongo.return_value = self.associations
q = mongoengine.Q(foo='bar')

list(repo_controller.get_associated_unit_ids('repo1', 'demo_model', q))
Expand Down

0 comments on commit 3fbb132

Please sign in to comment.