Group XForm lookups in case.get_forms

This is a nice win.  There's a slow (custom) report using this call on every row.  In local testing it took around a half a second per call.  This change brings that to around 0.05s (varying per case, of course), which represents around a 10x speed-up.  The result is still wrapped, and it's a list (not iterator), so the API should be unchanged.
Nice
On Jun 23, 2014 6:23 PM, "Ethan Soergel" <notifications@github.com> wrote:

> In casexml/apps/case/models.py:
>
> > @@ -490,14 +490,8 @@ def get_forms(self):
> >          Gets the form docs associated with a case. If it can't find a form
> >          it won't be included.
> >          """
> > -        def _get(id):
> > -            try:
> > -                return XFormInstance.get(id)
> > -            except ResourceNotFound:
> > -                return None
> > -
> > -        forms = [_get(id) for id in self.xform_ids]
> > -        return [form for form in forms if form]
> > +        forms = iter_docs(self.get_db(), self.xform_ids)
> > +        return [XFormInstance(form) for form in forms]
>
> It just skips it. I tested it out with a list containing three real form
> ids and a non-existent one, and it returned three form objects.
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/dimagi/casexml/pull/230/files#r14103679>.
>