зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1293790 - Implement getPlainTopSites query r=grisha
ActivityStream's topsites won't support pinned sites for now, this allows us to use a simpler query that only retrieves topsites without the complexity of a temporary table to merge pinned sites. This results in some duplication between the old and new topsites queries, however eventually we're going to want to get rid of one of these queries (we don't know whether ActivityStream will support pinned sites in the future yet, so we definitely want to keep the pinned query for now - it's also needed for the old topsites panel). MozReview-Commit-ID: AQyzXHGl3Cf --HG-- extra : rebase_source : 6830c50d30a326dc7080ce720d4c1890dbab8e32
This commit is contained in:
Родитель
51322da3c0
Коммит
8132366cce
|
@ -45,6 +45,7 @@ public class BrowserContract {
|
|||
public static final String PARAM_PROFILE_PATH = "profilePath";
|
||||
public static final String PARAM_LIMIT = "limit";
|
||||
public static final String PARAM_SUGGESTEDSITES_LIMIT = "suggestedsites_limit";
|
||||
public static final String PARAM_TOPSITES_DISABLE_PINNED = "topsites_disable_pinned";
|
||||
public static final String PARAM_IS_SYNC = "sync";
|
||||
public static final String PARAM_SHOW_DELETED = "show_deleted";
|
||||
public static final String PARAM_IS_TEST = "test";
|
||||
|
|
|
@ -43,6 +43,7 @@ import android.content.UriMatcher;
|
|||
import android.database.Cursor;
|
||||
import android.database.DatabaseUtils;
|
||||
import android.database.MatrixCursor;
|
||||
import android.database.MergeCursor;
|
||||
import android.database.SQLException;
|
||||
import android.database.sqlite.SQLiteCursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
|
@ -794,6 +795,69 @@ public class BrowserProvider extends SharedBrowserDatabaseProvider {
|
|||
return updated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get topsites by themselves, without the inclusion of pinned sites. Suggested sites
|
||||
* will be appended (if necessary) to the end of the list in order to provide up to PARAM_LIMIT items.
|
||||
*/
|
||||
private Cursor getPlainTopSites(final Uri uri) {
|
||||
final SQLiteDatabase db = getReadableDatabase(uri);
|
||||
|
||||
final String limitParam = uri.getQueryParameter(BrowserContract.PARAM_LIMIT);
|
||||
final int limit;
|
||||
if (limitParam != null) {
|
||||
limit = Integer.parseInt(limitParam);
|
||||
} else {
|
||||
limit = 12;
|
||||
}
|
||||
|
||||
// Filter out: unvisited pages (history_id == -1) pinned (and other special) sites, deleted sites,
|
||||
// and about: pages.
|
||||
final String ignoreForTopSitesWhereClause =
|
||||
"(" + Combined.HISTORY_ID + " IS NOT -1)" +
|
||||
" AND " +
|
||||
Combined.URL + " NOT IN (SELECT " +
|
||||
Bookmarks.URL + " FROM " + TABLE_BOOKMARKS + " WHERE " +
|
||||
DBUtils.qualifyColumn(TABLE_BOOKMARKS, Bookmarks.PARENT) + " < " + Bookmarks.FIXED_ROOT_ID + " AND " +
|
||||
DBUtils.qualifyColumn(TABLE_BOOKMARKS, Bookmarks.IS_DELETED) + " == 0)" +
|
||||
" AND " +
|
||||
"(" + Combined.URL + " NOT LIKE ?)";
|
||||
|
||||
final String[] ignoreForTopSitesArgs = new String[] {
|
||||
AboutPages.URL_FILTER
|
||||
};
|
||||
|
||||
final Cursor c = db.rawQuery("SELECT " +
|
||||
Bookmarks._ID + ", " +
|
||||
Combined.BOOKMARK_ID + ", " +
|
||||
Combined.HISTORY_ID + ", " +
|
||||
Bookmarks.URL + ", " +
|
||||
Bookmarks.TITLE + ", " +
|
||||
Combined.HISTORY_ID + ", " +
|
||||
TopSites.TYPE_TOP + " AS " + TopSites.TYPE +
|
||||
" FROM " + Combined.VIEW_NAME +
|
||||
" WHERE " + ignoreForTopSitesWhereClause +
|
||||
" ORDER BY " + BrowserContract.getCombinedFrecencySortOrder(true, false) +
|
||||
" LIMIT " + limit,
|
||||
ignoreForTopSitesArgs);
|
||||
|
||||
c.setNotificationUri(getContext().getContentResolver(),
|
||||
BrowserContract.AUTHORITY_URI);
|
||||
|
||||
if (c.getCount() == limit) {
|
||||
return c;
|
||||
}
|
||||
|
||||
// If we don't have enough data: get suggested sites too
|
||||
final SuggestedSites suggestedSites = GeckoProfile.get(getContext(), uri.getQueryParameter(BrowserContract.PARAM_PROFILE)).getDB().getSuggestedSites();
|
||||
|
||||
final Cursor suggestedSitesCursor = suggestedSites.get(limit - c.getCount());
|
||||
|
||||
return new MergeCursor(new Cursor[]{
|
||||
c,
|
||||
suggestedSitesCursor
|
||||
});
|
||||
}
|
||||
|
||||
private Cursor getTopSites(final Uri uri) {
|
||||
// In order to correctly merge the top and pinned sites we:
|
||||
//
|
||||
|
@ -946,10 +1010,10 @@ public class BrowserProvider extends SharedBrowserDatabaseProvider {
|
|||
// with -1 to represent no-sites, which allows us to directly add 1 to obtain the expected value
|
||||
// regardless of whether a position was actually retrieved.
|
||||
final String blanksLimitClause = " LIMIT MAX(0, " +
|
||||
"COALESCE((SELECT " + Bookmarks.POSITION + " " + pinnedSitesFromClause + "), -1) + 1" +
|
||||
" - (SELECT COUNT(*) " + pinnedSitesFromClause + ")" +
|
||||
" - (SELECT COUNT(*) FROM " + TABLE_TOPSITES + ")" +
|
||||
")";
|
||||
"COALESCE((SELECT " + Bookmarks.POSITION + " " + pinnedSitesFromClause + "), -1) + 1" +
|
||||
" - (SELECT COUNT(*) " + pinnedSitesFromClause + ")" +
|
||||
" - (SELECT COUNT(*) FROM " + TABLE_TOPSITES + ")" +
|
||||
")";
|
||||
|
||||
db.beginTransaction();
|
||||
try {
|
||||
|
@ -1077,7 +1141,11 @@ public class BrowserProvider extends SharedBrowserDatabaseProvider {
|
|||
final int match = URI_MATCHER.match(uri);
|
||||
|
||||
if (match == TOPSITES) {
|
||||
return getTopSites(uri);
|
||||
if (uri.getBooleanQueryParameter(BrowserContract.PARAM_TOPSITES_DISABLE_PINNED, false)) {
|
||||
return getPlainTopSites(uri);
|
||||
} else {
|
||||
return getTopSites(uri);
|
||||
}
|
||||
}
|
||||
|
||||
SQLiteDatabase db = getReadableDatabase(uri);
|
||||
|
|
|
@ -80,6 +80,7 @@ public class SuggestedSites {
|
|||
BrowserContract.SuggestedSites._ID,
|
||||
BrowserContract.SuggestedSites.URL,
|
||||
BrowserContract.SuggestedSites.TITLE,
|
||||
BrowserContract.Combined.HISTORY_ID
|
||||
};
|
||||
|
||||
private static final String JSON_KEY_URL = "url";
|
||||
|
@ -478,7 +479,15 @@ public class SuggestedSites {
|
|||
Log.d(LOGTAG, "Number of suggested sites: " + sitesCount);
|
||||
|
||||
final int maxCount = Math.min(limit, sitesCount);
|
||||
// History IDS: real history is positive, -1 is no history id in the combined table
|
||||
// hence we can start at -2 for suggested sites
|
||||
int id = -1;
|
||||
for (Site site : cachedSites.values()) {
|
||||
// Decrement ID here: this ensure we have a consistent ID to URL mapping, even if items
|
||||
// are removed. If we instead decremented at the point of insertion we'd end up with
|
||||
// ID conflicts when a suggested site is removed. (note that cachedSites does not change
|
||||
// while we're already showing topsites)
|
||||
--id;
|
||||
if (cursor.getCount() == maxCount) {
|
||||
break;
|
||||
}
|
||||
|
@ -491,9 +500,10 @@ public class SuggestedSites {
|
|||
|
||||
if (restrictedProfile == site.restricted) {
|
||||
final RowBuilder row = cursor.newRow();
|
||||
row.add(-1);
|
||||
row.add(id);
|
||||
row.add(site.url);
|
||||
row.add(site.title);
|
||||
row.add(id);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче