Need help with SWQL query that is timing out after 30 seconds

This customer query is running on a dashboard widget, and it times out exactly after 30 seconds.  I tried to find any setting that will allow it to run for longer but even after setting a number of settings, it still times out after 30 seconds.

Here is the query - I can verify that query is valid but needs about 90 seconds to run.  I there anything to make it more efficient?

select n.caption as [Device] 
-- shows the current status icon 
, '/Orion/images/StatusIcons/Small-' + n.StatusIcon AS [_IconFor_Device] 
-- makes a clickable link to the node details 
, n.DetailsUrl as [_linkfor_Device] 

-- shows the timestamp of the down event, if there is no timestamp then is says the event was greater than the number of days in your event retention settings 
, isnull(tostring(t2.[Down Event]),concat('Greater than ',(SELECT CurrentValue FROM Orion.Settings where settingid='SWNetPerfMon-Settings-Retain Events'),' days ago')) as [Down Event] 
-- shows the timestamp of the up event, unless the object is still down 
, isnull(tostring(t2.[Up Event]),'Still Down') as [Up Event] 
-- figures out the minutes between the down and up events, if the object is still down it counts from the down event to now, displays 99999 if we cannot accurately determine the original downtime, and  
, isnull(MINUTEDIFF(t2.[Down Event], isnull(t2.[Up Event],GETDATE())),99999) as Minutes 

from orion.nodes n 
left join (SELECT     
 -- Device nodeid used for our join    
 -- Down Event time stamp in local time zone     
 ,ToLocal(StartTime.EventTime) AS [Down Event]     

 -- Up Event time stamp in local time zone     
 ,(SELECT TOP 1     
 ToLocal(EventTime) AS [EventTime]     
 FROM Orion.Events AS [EndTime]     
-- picks the first up event that is newer than the down event for this node 
 WHERE EndTime.EventTime >= StartTime.EventTime    
-- EventType 5 is a node up
 AND EndTime.EventType = 5     
AND EndTime.NetObjectID = StartTime.NetObjectID     
 AND EventTime IS NOT NULL     
ORDER BY EndTime.EventTime     
 ) AS [Up Event]     
-- This is the table we are querying     
FROM Orion.Events StartTime     
-- EventType 1 is a node down 
WHERE StartTime.EventType = 1 

) t2 on n.NodeID = t2.nodeid 
-- this is how I catch nodes that are down but have aged out of the events table 
where (n.status = 2 or t2.nodeid is not null and (n.CustomProperties.Managedby = 'WatechNOC')) 
-- If you want to filter the results to only show outages of a minimum duration uncomment the below line 
and MINUTEDIFF(isnull(t2.[Down Event],(GETUTCDATE()-30)), isnull(t2.[Up Event],GETUTCDATE())) >  2
-- if you want to use this query in a search box of the Custom Query resource uncomment the below line 
--and n.Caption like '%${SEARCH_STRING}%' 
order by t2.[down event] desc 

  • Here is the error I get in SWQL studio

    2021-03-16 09:00:19,239 [137] ERROR SolarWinds.InformationService.Core.InformationService - SWQL Studio (null)  Exception caught in method SolarWinds.InformationService.Core.InformationService.RunQuery
    System.Data.SqlClient.SqlException (0x80131904): Execution Timeout Expired.  The timeout period elapsed prior to completion of the operation or the server is not responding. ---> System.ComponentModel.Win32Exception (0x80004005): The wait operation timed out
       at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
       at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
       at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
       at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
       at System.Data.SqlClient.SqlDataReader.get_MetaData()
       at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
       at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
       at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
       at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
       at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
       at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior)
       at SolarWinds.InformationService.DataProviders.SqlQueryRelation.<GetEnumerator>d__8.MoveNext()
       at SolarWinds.Data.Query.PhysicalQueryPlan.ProviderPassThroughScanOp.<GetEnumeratorInternal>d__5.MoveNext()
       at SolarWinds.Data.Query.QueryStatisticsEnumerator.MoveNext()
       at SolarWinds.Data.Query.PhysicalQueryPlan.ProjectOp.<GetEnumeratorInternal>d__7.MoveNext()
       at SolarWinds.Data.Query.QueryStatisticsEnumerator.MoveNext()
       at SolarWinds.Data.Query.PhysicalQueryPlan.PhysicalQueryPlan.<GetEnumerator>d__4.MoveNext()
       at SolarWinds.InformationService.Core.InformationService.RowsCountingQueryResultReader.MoveNext()
       at SolarWinds.InformationService.Serialization.XmlResponseSerializer..ctor(IQueryResultReader reader, IQueryExecutionPlan queryExecutionPlan, Boolean includeQueryPlan, IQueryStatisticsContext statistics, I18n i18N)
       at SolarWinds.InformationService.Serialization.XmlSerializer.Serialize(String query, IQueryExecutionPlan queryExecutionPlan, IQueryResultReader reader, Boolean isBase64EncodingAccepted, IMessageFormatterStrategy messageFormatterStrategy)
       at SolarWinds.InformationService.Core.InformationService.RunQuery(String query, IDictionary`2 parameters, IDataSerializer serializer, IMessageFormatterStrategy messageFormatterStrategy)
    Error Number:-2,State:0,Class:11