@jameslian - Your code assumes that no two uids will ever have the same lastEventTime. Is this a valid, system-enforced assumption? If not, then you must add uid to your transaction command.
However, it's probably irrelevant, because you are using a transaction command - which is computationally expensive, and then throwing away the results in your stats command by just counting it.
For your stats command, you only need two data fields, lastAcctSts and uid . The reset_after and reset_before clauses presume that there may be more than one set of transactions per uid , however, you are counting all uids, not just the distinct ones, grouped by lastAccountSts .
OvVerall, there HAS to be a much more efficient way of doing this. If you give us examples of the data, as @woodcock has requested, then we can help you do it much more efficiently.
... View more