function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Fahad Khan 2Fahad Khan 2 

Query execution Delay, too much!

I have an apex rest webservice and it has query where it takes around 30 to 40 seconds to execute. query is as follows and debug logs are attached. Funny and frustrating thing is for the first time when i call that WS it takes 30 to 40 seconds but if i try to call the same again it takes no time to execute. and if i wait like 1.5 to 2 hours and try again to execute that call it again takes 30 to 40 seconds. I am not sure if oracle keeps compiled queries or what. please help. Thanks in advance

SOQL: [Select  ActivityDateTime, subject
                                    From Event
                                    Where ActivityDateTime > :now and 
                                    isChild = false and
                                    (/*Subject Like '%handover%' OR*/ Subject Like '%survey appt%' OR
                                     /*   Subject Like '%remeasure%' OR Subject Like '%spot check%' OR*/
                                        Subject Like '%misc appt%' OR
                                        Subject Like '%showroom visit%' OR Subject Like '%general appt%' ) and
                                    ActivityDateTime <= NEXT_N_DAYS:14 ]


Debug logs both executions:
User-added image