Bug 697747 - Limit the number of rows returned in AwesomeBar queries (r=mfinkle)
authorLucas Rocha <lucasr@mozilla.com>
Fri, 28 Oct 2011 15:57:09 +0100
changeset 83308 12f6c3a2b6658174ba39a9db31f951a8e03b9a51
parent 83307 cdb0a41ea68c991f1d2823f9e7cadd85ddcb8964
child 83309 403d217a6c098cf7c794ce61fddb509fcc66aa51
push id519
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 00:38:35 +0000
treeherdermozilla-beta@788ea1ef610b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs697747
milestone10.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 697747 - Limit the number of rows returned in AwesomeBar queries (r=mfinkle)
embedding/android/AwesomeBarTabs.java
--- a/embedding/android/AwesomeBarTabs.java
+++ b/embedding/android/AwesomeBarTabs.java
@@ -80,16 +80,20 @@ public class AwesomeBarTabs extends TabH
 
     private Context mContext;
     private OnUrlOpenListener mUrlOpenListener;
 
     private SimpleCursorAdapter mAllPagesAdapter;
     private SimpleCursorAdapter mBookmarksAdapter;
     private SimpleExpandableListAdapter mHistoryAdapter;
 
+    // FIXME: This value should probably come from a
+    // prefs key (just like XUL-based fennec)
+    private static final int MAX_RESULTS = 100;
+
     public interface OnUrlOpenListener {
         public abstract void onUrlOpen(AwesomeBarTabs tabs, String url);
     }
 
     private class HistoryListAdapter extends SimpleExpandableListAdapter {
         public HistoryListAdapter(Context context, List<? extends Map<String, ?>> groupData,
                 int groupLayout, String[] groupFrom, int[] groupTo,
                 List<? extends List<? extends Map<String, ?>>> childData,
@@ -186,33 +190,29 @@ public class AwesomeBarTabs extends TabH
                 }
             });
 
             bookmarksList.setAdapter(mBookmarksAdapter);
         }
     }
 
     private class HistoryQueryTask extends AsyncTask<Void, Void, Cursor> {
-        // FIXME: This value should probably come from a
-        // prefs key (just like XUL-based fennec)
-        private static final int MAX_RESULTS = 100;
-
         private static final long MS_PER_DAY = 86400000;
         private static final long MS_PER_WEEK = MS_PER_DAY * 7;
 
         protected Cursor doInBackground(Void... arg0) {
             ContentResolver resolver = mContext.getContentResolver();
 
             return resolver.query(Browser.BOOKMARKS_URI,
                                   null,
                                   // Bookmarks that have not been visited have a date value
                                   // of 0, so don't pick them up in the history view.
                                   Browser.BookmarkColumns.DATE + " > 0",
                                   null,
-                                  Browser.BookmarkColumns.DATE + " DESC");
+                                  Browser.BookmarkColumns.DATE + " DESC LIMIT " + MAX_RESULTS);
         }
 
         public Map<String,?> createHistoryItem(Cursor cursor) {
             Map<String,Object> historyItem = new HashMap<String,Object>();
 
             String url = cursor.getString(cursor.getColumnIndexOrThrow(AwesomeBar.URL_KEY));
             String title = cursor.getString(cursor.getColumnIndexOrThrow(AwesomeBar.TITLE_KEY));
             byte[] favicon = cursor.getBlob(cursor.getColumnIndexOrThrow(Browser.BookmarkColumns.FAVICON));
@@ -291,17 +291,17 @@ public class AwesomeBarTabs extends TabH
             // Move cursor before the first row in preparation
             // for the iteration.
             cursor.moveToPosition(-1);
 
             // Split the history query results into adapters per time
             // section (today, yesterday, week, older). Queries on content
             // Browser content provider don't support limitting the number
             // of returned rows so we limit it here.
-            while (cursor.moveToNext() && cursor.getPosition() < MAX_RESULTS) {
+            while (cursor.moveToNext()) {
                 long time = cursor.getLong(cursor.getColumnIndexOrThrow(Browser.BookmarkColumns.DATE));
                 HistorySection itemSection = getSectionForTime(time, today);
 
                 if (groups == null)
                     groups = new LinkedList<Map<String,?>>();
 
                 if (childrenLists == null)
                     childrenLists = new LinkedList<List<Map<String,?>>>();
@@ -440,17 +440,17 @@ public class AwesomeBarTabs extends TabH
                                       // (see comment earlier in this file).
                                       "(" + Browser.BookmarkColumns.URL + " LIKE ? OR " + Browser.BookmarkColumns.TITLE + " LIKE ?)"
                                         + " AND LENGTH(" + Browser.BookmarkColumns.URL + ") > 0", 
                                       new String[] {"%" + constraint.toString() + "%", "%" + constraint.toString() + "%",},
                                       // ORDER BY is number of visits times a multiplier from 1 - 120 of how recently the site 
                                       // was accessed with a site accessed today getting 120 and a site accessed 119 or more 
                                       // days ago getting 1
                                       Browser.BookmarkColumns.VISITS + " * MAX(1, (" +
-                                      Browser.BookmarkColumns.DATE + " - " + new Date().getTime() + ") / 86400000 + 120) DESC");   
+                                      Browser.BookmarkColumns.DATE + " - " + new Date().getTime() + ") / 86400000 + 120) DESC LIMIT " + MAX_RESULTS);
             }
         });
 
         final ListView allPagesList = (ListView) findViewById(R.id.all_pages_list);
 
         allPagesList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
             public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                 handleItemClick(allPagesList, position);