Bug 1428165 - Part 2: fix history expiration query r=nalexander draft
authorGrigory Kruglov <gkruglov@mozilla.com>
Thu, 04 Jan 2018 23:15:42 -0500
changeset 716658 9f54208c3dd0de8cf602f0e34376e1ac0a511017
parent 716657 143fbcbad3b7a822650c1e132f5ae809c4399ab8
child 745075 ec9d7a2712d82f98d81a5ec91f3d96a9c09ab26b
push id94481
push userbmo:gkruglov@mozilla.com
push dateSat, 06 Jan 2018 02:26:38 +0000
reviewersnalexander
bugs1428165
milestone59.0a1
Bug 1428165 - Part 2: fix history expiration query r=nalexander 'modified' value might be missing; in SQLite, max(123, null) is null, and so we must coalesce fields which might be missing values. MozReview-Commit-ID: Bn1P0kdaHHT
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
@@ -473,18 +473,22 @@ public class BrowserProvider extends Sha
             return;
         }
 
         final long toRemove = rows - retain;
         debug("Expiring at most " + toRemove + " rows earlier than " + keepAfter + ".");
 
         final String sql;
         if (keepAfter > 0) {
+            // See Bug 1428165: 'modified' value might be missing; assume 0 if that's the case.
             sql = "DELETE FROM " + TABLE_HISTORY + " " +
-                  "WHERE MAX(" + History.DATE_LAST_VISITED + ", " + History.DATE_MODIFIED + ") < " + keepAfter + " " +
+                  "WHERE MAX("
+                    + History.DATE_LAST_VISITED + ", " +
+                    "COALESCE(" + History.DATE_MODIFIED + ", 0))" +
+                  " < " + keepAfter + " " +
                   " AND " + History._ID + " IN ( SELECT " +
                     History._ID + " FROM " + TABLE_HISTORY + " " +
                     "ORDER BY " + History.DATE_LAST_VISITED + " ASC LIMIT " + toRemove +
                   ")";
         } else {
             sql = "DELETE FROM " + TABLE_HISTORY + " WHERE " + History._ID + " " +
                   "IN ( SELECT " + History._ID + " FROM " + TABLE_HISTORY + " " +
                   "ORDER BY " + History.DATE_LAST_VISITED + " ASC LIMIT " + toRemove + ")";