I asked this on someone else's question: https://community.atlassian.com/t5/Confluence-questions/How-to-query-active-users-in-Confluence/qaq-p/24532?_ga=2.208006866.1942474880.1528220541-1332829241.1528220541 but never got a response, so I'm re-asking it as it's own question now.
When we were under 500 users the below macro worked perfectly for me; however, now that we are over 900 users - the system times out. Is there a better way to get all Confluence users name and last login for audit purposes?
## Macro title: Last Login
## Macro has a body: N
## Body processing: Selected body processing option
## Output: Selected output option
##
## Developed by: Andrew Frayling
## Date created: 11/02/2012
## Installed by: <your name>
## Macro to display the last login date of users who have access to the current space
## @noparams
#set($containerManagerClass = $content.class.forName('com.atlassian.spring.container.ContainerManager'))
#set($getInstanceMethod = $containerManagerClass.getDeclaredMethod('getInstance',null))
#set($containerManager = $getInstanceMethod.invoke(null,null))
#set($containerContext = $containerManager.containerContext)
#set($loginManager = $containerContext.getComponent('loginManager'))
#set($users = $userAccessor.getUsers())
<table class="confluenceTable">
<tr>
<th class="confluenceTh">User</th>
<th class="confluenceTh">Last Successful Login</th>
</tr>
#foreach($user in $users)
## list the last login date of users who can view the current space
<tr>
<td class="confluenceTd">#usernameLink($user.name)</td>
#if (!$loginManager.getLoginInfo($user).lastSuccessfulLoginDate)
<td class="confluenceTd" style="background-color:#ff0000"><strong>NEVER</strong></td>
#else
<td class="confluenceTd">$action.dateFormatter.formatDateTime($loginManager.getLoginInfo($user).lastSuccessfulLoginDate)</td>
#end
</tr>
#end
</table>