Patient Queue Module performance issue

Module: Queue

Module Version: 2.9.0

System Version: Version: 2.7.7 Build 0

Issue or Question: We recently started using service queues and noticed an issue with performance. The queries would take a long time sometimes to return data despite the fact that the queue_entry table had less than 50 rows. I looked at the query generated when fetching the queue entry data and it was 800+ lines, with the table doing 30+ joins. Is it possible to optimize this module for better performance ?

API Endpoint when fetching queues :

`https://{{base_url}}/openmrs/ws/rest/v1/queue-entry?v=custom:(uuid,display,queue,status,patient:(uuid,display,person,identifiers:(uuid,display,identifier,identifierType)),visit:(uuid,display,startDatetime,encounters:(uuid,display,diagnoses,encounterDatetime,encounterType,obs,encounterProviders,voided),attributes:(uuid,display,value,attributeType)),priority,priorityComment,sortWeight,startedAt,endedAt,locationWaitingFor,queueComingFrom,providerWaitingFor,previousQueueEntry)&totalCount=true&isEnded=false&location=08feae7c-1352-11df-a1f1-0026b9348838`

Should i also share the query? Its very long.

Kindly assist @dkayiwa

Could it be the the reason for the Slow performance is related to v=custom:(…)? you can try to reduce the presentation by locating the API call you are using that appears something like this `/ws/rest/v1/queue-entry?v=custom:(uuid,display,queue,status,patient:(…),visit:(…),priority,sortWeight,startedAt,endedAt,…)` then remove deeply nested objects that cause excessive joins. Specifically

  • encounters

  • obs

  • diagnoses

  • encounterProviders

  • visit.attributes

  • previousQueueEntry

  • providerWaitingFor.person.attributes

Then replace it with a lightweight v=custom, keeping only fields your UI actually needs eg

v=custom:(uuid,queue,status,
          patient:(uuid,display,identifiers:(identifier)),
          visit:(uuid,startDatetime),
          priority,priorityComment,sortWeight,startedAt,
          locationWaitingFor:(uuid,display),
          queueComingFrom:(uuid,display))

then test the API to ensure it still works.