From: Damyan Ivanov Date: Fri, 26 Mar 2021 16:53:58 +0000 (+0200) Subject: minor optimization in getting next generation X-Git-Tag: v0.18.0~98 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=9d9baff5b649eda7609fe77fe6d6aadf986bb300;p=mobile-ledger.git minor optimization in getting next generation --- diff --git a/app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java b/app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java index a7a6eeab..6f70bda5 100644 --- a/app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java +++ b/app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java @@ -547,27 +547,22 @@ public final class MobileLedgerProfile { this.themeHue = themeHue; } public int getNextTransactionsGeneration(SQLiteDatabase db) { - int generation = 1; try (Cursor c = db.rawQuery( "SELECT generation FROM transactions WHERE profile_id=? LIMIT 1", new String[]{String.valueOf(id)})) { - if (c.moveToFirst()) { - generation = c.getInt(0) + 1; - } + if (c.moveToFirst()) + return c.getInt(0) + 1; } - return generation; + return 1; } private int getNextAccountsGeneration(SQLiteDatabase db) { - int generation = 1; try (Cursor c = db.rawQuery("SELECT generation FROM accounts WHERE profile_id=? LIMIT 1", - new String[]{String.valueOf(id)})) - { - if (c.moveToFirst()) { - generation = c.getInt(0) + 1; - } + new String[]{String.valueOf(id)})) { + if (c.moveToFirst()) + return c.getInt(0) + 1; } - return generation; + return 1; } private void deleteNotPresentAccounts(SQLiteDatabase db, int generation) { Logger.debug("db/benchmark", "Deleting obsolete accounts");