Bug 709078 - Only load necessary cols on awesomescreen filter and about:home queries (r=blassey)

Top Sites in about:home doesn't need favicons and awesomescreen filter doesn't
need thumbnails.
This commit is contained in:
Lucas Rocha 2012-01-19 17:23:10 +00:00
parent 9ca4b12fb5
commit 325ed29249
4 changed files with 58 additions and 18 deletions

View File

@ -173,7 +173,7 @@ public class AboutHomeContent extends ScrollView {
activity.stopManagingCursor(mCursor);
ContentResolver resolver = GeckoApp.mAppContext.getContentResolver();
mCursor = BrowserDB.filter(resolver, "", NUMBER_OF_TOP_SITES_PORTRAIT, "about:%");
mCursor = BrowserDB.getTopSites(resolver, NUMBER_OF_TOP_SITES_PORTRAIT);
activity.startManagingCursor(mCursor);
mTopSitesAdapter = new TopSitesCursorAdapter(activity,

View File

@ -63,13 +63,9 @@ public class AndroidBrowserDB implements BrowserDB.BrowserDBIface {
private static final Uri BOOKMARKS_CONTENT_URI_POST_11 = Uri.parse("content://com.android.browser/bookmarks");
public Cursor filter(ContentResolver cr, CharSequence constraint, int limit, CharSequence urlFilter) {
private Cursor filterAllSites(ContentResolver cr, String[] projection, CharSequence constraint, int limit, CharSequence urlFilter) {
Cursor c = cr.query(Browser.BOOKMARKS_URI,
new String[] { URL_COLUMN_ID,
BookmarkColumns.URL,
BookmarkColumns.TITLE,
BookmarkColumns.FAVICON,
URL_COLUMN_THUMBNAIL },
projection,
// The length restriction on URL is for the same reason as in the general bookmark query
// (see comment earlier in this file).
(urlFilter != null ? "(" + Browser.BookmarkColumns.URL + " NOT LIKE ? ) AND " : "" ) +
@ -86,6 +82,28 @@ public class AndroidBrowserDB implements BrowserDB.BrowserDBIface {
return new AndroidDBCursor(c);
}
public Cursor filter(ContentResolver cr, CharSequence constraint, int limit) {
return filterAllSites(cr,
new String[] { URL_COLUMN_ID,
BookmarkColumns.URL,
BookmarkColumns.TITLE,
BookmarkColumns.FAVICON },
constraint,
limit,
null);
}
public Cursor getTopSites(ContentResolver cr, int limit) {
return filterAllSites(cr,
new String[] { URL_COLUMN_ID,
BookmarkColumns.URL,
BookmarkColumns.TITLE,
URL_COLUMN_THUMBNAIL },
"",
limit,
BrowserDB.ABOUT_PAGES_URL_FILTER);
}
public void updateVisitedHistory(ContentResolver cr, String uri) {
Browser.updateVisitedHistory(cr, uri, true);
}

View File

@ -42,6 +42,8 @@ import android.database.Cursor;
import android.graphics.drawable.BitmapDrawable;
public class BrowserDB {
public static String ABOUT_PAGES_URL_FILTER = "about:%";
public static interface URLColumns {
public static String URL = "url";
public static String TITLE = "title";
@ -53,7 +55,9 @@ public class BrowserDB {
private static BrowserDBIface sDb;
public interface BrowserDBIface {
public Cursor filter(ContentResolver cr, CharSequence constraint, int limit, CharSequence urlFilter);
public Cursor filter(ContentResolver cr, CharSequence constraint, int limit);
public Cursor getTopSites(ContentResolver cr, int limit);
public void updateVisitedHistory(ContentResolver cr, String uri);
@ -87,12 +91,12 @@ public class BrowserDB {
sDb = new LocalBrowserDB(BrowserContract.DEFAULT_PROFILE);
}
public static Cursor filter(ContentResolver cr, CharSequence constraint, int limit, CharSequence urlFilter) {
return sDb.filter(cr, constraint, limit, urlFilter);
public static Cursor filter(ContentResolver cr, CharSequence constraint, int limit) {
return sDb.filter(cr, constraint, limit);
}
public static Cursor filter(ContentResolver cr, CharSequence constraint, int limit) {
return sDb.filter(cr, constraint, limit, null);
public static Cursor getTopSites(ContentResolver cr, int limit) {
return sDb.getTopSites(cr, limit);
}
public static void updateVisitedHistory(ContentResolver cr, String uri) {

View File

@ -80,13 +80,9 @@ public class LocalBrowserDB implements BrowserDB.BrowserDBIface {
return uri.buildUpon().appendQueryParameter(BrowserContract.PARAM_PROFILE, mProfile).build();
}
public Cursor filter(ContentResolver cr, CharSequence constraint, int limit, CharSequence urlFilter) {
private Cursor filterAllSites(ContentResolver cr, String[] projection, CharSequence constraint, int limit, CharSequence urlFilter) {
Cursor c = cr.query(appendProfileAndLimit(History.CONTENT_URI, limit),
new String[] { History._ID,
History.URL,
History.TITLE,
History.FAVICON,
History.THUMBNAIL },
projection,
(urlFilter != null ? "(" + History.URL + " NOT LIKE ? ) AND " : "" ) +
"(" + History.URL + " LIKE ? OR " + History.TITLE + " LIKE ?)",
urlFilter == null ? new String[] {"%" + constraint.toString() + "%", "%" + constraint.toString() + "%"} :
@ -100,6 +96,28 @@ public class LocalBrowserDB implements BrowserDB.BrowserDBIface {
return new LocalDBCursor(c);
}
public Cursor filter(ContentResolver cr, CharSequence constraint, int limit) {
return filterAllSites(cr,
new String[] { History._ID,
History.URL,
History.TITLE,
History.FAVICON },
constraint,
limit,
null);
}
public Cursor getTopSites(ContentResolver cr, int limit) {
return filterAllSites(cr,
new String[] { History._ID,
History.URL,
History.TITLE,
History.THUMBNAIL },
"",
limit,
BrowserDB.ABOUT_PAGES_URL_FILTER);
}
private void truncateHistory(ContentResolver cr) {
Cursor cursor = null;