From 944e87f14232fc2220a62d7a68c69f0917868788 Mon Sep 17 00:00:00 2001 From: Mark Finkle Date: Tue, 29 Dec 2015 20:50:46 -0500 Subject: [PATCH] Bug 1235637 - Provide a simple way to update history without needing a cursor r=rnewman --- .../org/mozilla/gecko/db/BrowserProvider.java | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/mobile/android/base/java/org/mozilla/gecko/db/BrowserProvider.java b/mobile/android/base/java/org/mozilla/gecko/db/BrowserProvider.java index fc58c6ad4401..bbab3ff8e38f 100644 --- a/mobile/android/base/java/org/mozilla/gecko/db/BrowserProvider.java +++ b/mobile/android/base/java/org/mozilla/gecko/db/BrowserProvider.java @@ -1011,7 +1011,17 @@ public class BrowserProvider extends SharedBrowserDatabaseProvider { String[] selectionArgs) { trace("Updating history on URI: " + uri); - int updated = 0; + final SQLiteDatabase db = getWritableDatabase(uri); + + if (!values.containsKey(History.DATE_MODIFIED)) { + values.put(History.DATE_MODIFIED, System.currentTimeMillis()); + } + + // Use the simple code path for easy updates. + if (!shouldIncrementVisits(uri)) { + trace("Updating history meta data only"); + return db.update(TABLE_HISTORY, values, selection, selectionArgs); + } final String[] historyProjection = new String[] { History._ID, // 0 @@ -1019,27 +1029,22 @@ public class BrowserProvider extends SharedBrowserDatabaseProvider { History.VISITS // 2 }; - final SQLiteDatabase db = getWritableDatabase(uri); final Cursor cursor = db.query(TABLE_HISTORY, historyProjection, selection, selectionArgs, null, null, null); - try { - if (!values.containsKey(Bookmarks.DATE_MODIFIED)) { - values.put(Bookmarks.DATE_MODIFIED, System.currentTimeMillis()); - } + int updated = 0; + try { while (cursor.moveToNext()) { long id = cursor.getLong(0); trace("Updating history entry with ID: " + id); - if (shouldIncrementVisits(uri)) { - long existing = cursor.getLong(2); - Long additional = values.getAsLong(History.VISITS); + long existing = cursor.getLong(2); + Long additional = values.getAsLong(History.VISITS); - // Increment visit count by a specified amount, or default to increment by 1 - values.put(History.VISITS, existing + ((additional != null) ? additional : 1)); - } + // Increment visit count by a specified amount, or default to increment by 1 + values.put(History.VISITS, existing + ((additional != null) ? additional : 1)); updated += db.update(TABLE_HISTORY, values, "_id = ?", new String[] { Long.toString(id) });