Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ef99555

Browse files
committed
Fixes slow CSV exports
For each split in every exported transaction, the code fetched the whole Account instance, including all its transactions with all their splits. This resulted in hundreds of thousands of requests with a medium-sized ledger. There was a cache mechanism, but it was local to one single transaction, thus essentially useless. Now, each split generates two requests, to get the account's name and full name. A better cache mechanism would speed this up further.
1 parent f69a609 commit ef99555

File tree

1 file changed

+2
-13
lines changed

1 file changed

+2
-13
lines changed

app/src/main/java/org/gnucash/android/export/csv/CsvTransactionsExporter.java

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,27 +99,16 @@ public List<String> generateExport() throws ExporterException {
9999
private void writeSplitsToCsv(@NonNull List<Split> splits, @NonNull CsvWriter writer) throws IOException {
100100
int index = 0;
101101

102-
Map<String, Account> uidAccountMap = new HashMap<>();
103-
104102
for (Split split : splits) {
105103
if (index++ > 0){ // the first split is on the same line as the transactions. But after that, we
106104
writer.write("" + mCsvSeparator + mCsvSeparator + mCsvSeparator + mCsvSeparator
107105
+ mCsvSeparator + mCsvSeparator + mCsvSeparator + mCsvSeparator);
108106
}
109107
writer.writeToken(split.getMemo());
110108

111-
//cache accounts so that we do not have to go to the DB each time
112109
String accountUID = split.getAccountUID();
113-
Account account;
114-
if (uidAccountMap.containsKey(accountUID)) {
115-
account = uidAccountMap.get(accountUID);
116-
} else {
117-
account = mAccountsDbAdapter.getRecord(accountUID);
118-
uidAccountMap.put(accountUID, account);
119-
}
120-
121-
writer.writeToken(account.getFullName());
122-
writer.writeToken(account.getName());
110+
writer.writeToken(mAccountsDbAdapter.getAccountFullName(accountUID));
111+
writer.writeToken(mAccountsDbAdapter.getAccountName(accountUID));
123112

124113
String sign = split.getType() == TransactionType.CREDIT ? "-" : "";
125114
writer.writeToken(sign + split.getQuantity().formattedString());

0 commit comments

Comments
 (0)