Reputation: 5
I have a Flask App that uses twilio. I display the total amount of incomingphonenumbers in an account/subaccount to the user.
Here is what I'm currently doing to get the total:
client = Client(accountsid,accounttoken)
# Get the list
pnlist = client.incoming_phone_numbers.list(limit=1)
# Get the length of the list
total = len(pnlist)
This takes upwards of 19 seconds just to get the numbers in the Master account. On top of that I have to repeat this for all subaccounts.
Is there a better way to just get the total numbers for a account/subaccount?
Thanks in advance!
Upvotes: 0
Views: 140
Reputation: 73029
Twilio developer evangelist here.
I would recommend that, rather than listing all the numbers every time you want to count them, you cache the count within your own database against the account.
You can then update the count either when you know it changes, if you are purchasing/releasing numbers via the API in your app, or periodically (say, once a day) with a background job.
Upvotes: 0