From: Thierry Parmentelat Date: Tue, 19 Aug 2014 18:07:27 +0000 (+0200) Subject: avoiding an API call if possible X-Git-Tag: sfa-3.1-10~1^2~4 X-Git-Url: http://git.onelab.eu/?p=sfa.git;a=commitdiff_plain;h=bacb024c0fca1d2a5dfe3e31e047a709ef1b293d avoiding an API call if possible --- diff --git a/sfa/planetlab/plslices.py b/sfa/planetlab/plslices.py index ed956874..0f4bd20b 100644 --- a/sfa/planetlab/plslices.py +++ b/sfa/planetlab/plslices.py @@ -503,8 +503,12 @@ class PlSlices: # about the last 2 sets, for managing keys, we need to trace back person_id -> user # and for this we need all the Person objects; we already have the target_existing ones - target_created_persons = self.driver.shell.GetPersons ({'peer_id':None, 'person_id':target_created_person_ids},person_fields) - persons_by_person_id = { person['person_id'] : person for person in target_existing_persons + target_created_persons } + # also we avoid issuing a call if possible + target_created_persons = [] if not target_created_person_ids \ + else driver.shell.GetPersons ({'peer_id':None, 'person_id':target_created_person_ids}, + person_fields) + persons_by_person_id = { person['person_id'] : person \ + for person in target_existing_persons + target_created_persons } def user_by_person_id (person_id): person = persons_by_person_id [person_id]