Bug 1235637 - Provide a simple way to update history without needing a cursor r=rnewman
authorMark Finkle <mfinkle@mozilla.com>
Tue, 29 Dec 2015 20:50:46 -0500
changeset 277880 2314a86a52ef77447be564e4649bc5437bd7ab92
parent 277879 e873ef1df11f7c0538ec2dd5f53a6568c4bb7005
child 277881 804529fa0c027b32e26edf310eb9c7cd65de9aa1
push id69628
push usercbook@mozilla.com
push dateWed, 30 Dec 2015 11:16:09 +0000
treeherdermozilla-inbound@b493cf33851f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrnewman
bugs1235637
milestone46.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1235637 - Provide a simple way to update history without needing a cursor r=rnewman
mobile/android/base/java/org/mozilla/gecko/db/BrowserProvider.java
--- a/mobile/android/base/java/org/mozilla/gecko/db/BrowserProvider.java
+++ b/mobile/android/base/java/org/mozilla/gecko/db/BrowserProvider.java
@@ -1006,45 +1006,50 @@ public class BrowserProvider extends Sha
 
         return 0;
     }
 
     private int updateHistory(Uri uri, ContentValues values, String selection,
             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
             History.URL,   // 1
             History.VISITS // 2
         };
 
-        final SQLiteDatabase db = getWritableDatabase(uri);
         final Cursor cursor = db.query(TABLE_HISTORY, historyProjection, selection,
                                        selectionArgs, null, null, null);
 
+        int updated = 0;
+
         try {
-            if (!values.containsKey(Bookmarks.DATE_MODIFIED)) {
-                values.put(Bookmarks.DATE_MODIFIED,  System.currentTimeMillis());
-            }
-
             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) });
             }
         } finally {
             cursor.close();
         }