instedd / verboice

Open source toolkit for voice services; with special focus to the needs of medium- and low-income countries, scalable services, and interacting with vulnerable populations
http://verboice.instedd.org/
GNU General Public License v3.0
43 stars 18 forks source link

Optimize curated addresses #945

Closed matiasgarciaisaia closed 4 months ago

matiasgarciaisaia commented 4 months ago

When queueing calls with a specific call flow from the Projects page, we first check we don't call the same Contact twice (ie, if the user pasted two different phones of the same contact at the same time).

If the project's address book grew large, the method is really slow when mapping contact addresses to contacts, because it loads every contact address for the project from the database - and iterating over them. We've seen this method take ~20 seconds with ~365k contacts in a production environment.

This PR changes the method so it only works with the Contacts of the given phone numbers instead of every contact of the project. We now do two queries to the DB instead of a single one, but we query via an index, and significantly reduce the amount of records to work with.

See #944

matiasgarciaisaia commented 4 months ago

@ggiraldez could you check the original commit (fee045a9b6f3f21434ea2f34169be0ea74ef4c67) to see if we're missing any test case?