[PD-732][PD-733] Fixed location sorting and slowness.

~~Works with mysql, not sure about sqlite (but production uses mysql so I don't know that it matters).~~ I just confirmed this works for sqlite as well.

Production currently throws a 500 if you try and refresh a page after sorting by location on the partner library. This fixes that.