From 9d9baff5b649eda7609fe77fe6d6aadf986bb300 Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Fri, 26 Mar 2021 18:53:58 +0200 Subject: [PATCH] minor optimization in getting next generation --- .../model/MobileLedgerProfile.java | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) 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"); -- 2.39.5