Skip to content
This repository has been archived by the owner on Oct 7, 2022. It is now read-only.

Performance fix for enterprise.retrieve #13

Open
GoogleCodeExporter opened this issue Sep 29, 2015 · 3 comments
Open

Performance fix for enterprise.retrieve #13

GoogleCodeExporter opened this issue Sep 29, 2015 · 3 comments

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?
1. Do a retrieve of 113 records by Id list.
2. It takes 2 minutes.
3. It took 113 API calls.

What is the expected output? What do you see instead?
The expected output is correct, but slow and expensive.
The attached code appears to product the same results, uses more memory,
but faster and less expensively. 

   def retrieve(
        self,
        fieldList,
        sObjectType,
        ids,
        ):
        '''
    Currently, this uses query() to emulate the retrieve() functionality, as suds' unmarshaller
    borks on the sf: prefix that Salesforce prepends to all fields other than Id and type (any
    fields not defined in the 'sObject' section of the Enterprise WSDL). This code used to
    do a single API query for each Id. This was both slow and expensive.
    '''
        if len(ids) == 0:
            return []
        idsin = ["'%s'" % id for id in ids]
        idsin = ",".join(idsin)
        idsin = "(%s)" % idsin
        sObjects = []
        queryString = 'SELECT Id, ' + fieldList + ' FROM ' \
            + sObjectType + ' WHERE Id in %s ' % idsin
        queryResult = self.query(queryString)
        resultsById = {}
        for record in queryResult.records:
            if record:
                sObject = self.generateObject(sObjectType)
                for (k, v) in record:
                    setattr(sObject, k, v)
            resultsById[sObject.Id] = sObject
        for id in ids:
            sObject = resultsById.get(id, None)
            if sObject:
                sObjects.append(sObject)
            else:
                sObjects.append(None)


        return self._handleResultTyping(sObjects)


Original issue reported on code.google.com by sean.t...@gmail.com on 6 Jul 2011 at 2:48

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant