cityofaustin / atd-data-tech

Austin Transportation Data & Technology Services
17 stars 2 forks source link

Prioritize and queue Signal Details API requests #1835

Open atdservicebot opened 4 years ago

atdservicebot commented 4 years ago

This issue follows the trail of #218. It would introduce a better pattern for managing multiple API calls for a single view (considering Knack rate limits), reduce maintenance, and improve extensibility.

What if all of our requests lived in an array prioritized by order of importance.

const apiRequests = [
      api.assets().map,
      api.assets().details,
      api.assets().serviceRequests,   
      api.assets().preventativeMaint,
      api.assets().detectors,
      api.assets().cameras,
      api.assets().workOrders,
      api.assets().signalPriority,
      api.assets().poleAttachments,
      api.assets().travelSensor,
      api.assets().apsButtonRequests,
      api.assets().cadStatus,
]

And then we could write a function that programmatically goes through that list and calls the api request with the item.id. That function could space all the calls by .250 sec so we're at most making 4 calls a second. And it makes it easier for us to add more features to this page in the future.

Resources: https://medium.com/better-programming/how-to-use-async-await-with-axios-in-react-e07daac2905f https://gist.github.com/wesbos/1866f918824936ffb73d8fd0b02879b4

Migrated from atd-mobile-signals-work-orders #220

amenity commented 2 years ago

@ChrispinP - did you mean to thaw this? 🧊 🌞

ChrispinP commented 2 years ago

@amenity negative. It might have unintentionally got grabbed during the board fixing.