Is there an efficient way of getting the last transaction date for an account?
I'm displaying a list of all the securities in all the investment accounts (about 1000 active and inactive). Producing the list takes milliseconds but getting the last transaction date takes over 7 seconds for the lot. Is there a more efficient/clever way than the following:
TxnSet txns = book.getTransactionSet().getTransactionsForAccount(secAcct);
txns.sortByField(AccountUtil.DATE);
int latestDate = txns.getLastTxn().getDateInt();
Thanks for any suggestions.
Comments are currently closed for this discussion. You can start a new one.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
1 Posted by Stuart Beesley ... on 18 Aug, 2021 07:08 PM
Probably not very helpful, but I see the internal MD code does this..:
TxnSet acctTxns = book.getTransactionSet().getTransactionsForAccount(account);
int lastDate = acctTxns.getLastTxn().getDateInt();
Which is identical to your code... So I somehow suspect that there is no particularly faster way..?
What about getting all txns (perhaps for all Investment Accounts) and iterating over the whole lot yourself and building a small table of last dates and then querying that.. Perhaps one call to getTransactions for all txns is faster than many calls per account..?
2 Posted by Bob B on 18 Aug, 2021 09:44 PM
Thanks I'll give that a try and report back.
3 Posted by Bob B on 18 Aug, 2021 10:26 PM
WOW Stuart that was a BRILLIANT suggestion. The timings went from over 7 seconds to about 0.013 seconds to generate the map of Account, LastTxDate Thanks so much.
4 Posted by Stuart Beesley ... on 18 Aug, 2021 10:59 PM
👍 +1 😃
Maddy closed this discussion on 20 Aug, 2021 01:57 PM.