Bug 1265708 - Post: query topsites metadata by URL without ref too r=sebastian
☠☠ backed out by 9f454bf15a8a ☠ ☠
authorAndrzej Hunt <ahunt@mozilla.com>
Fri, 03 Jun 2016 14:05:42 -0700
changeset 324864 67c37ed1a25f92cac6294cb70af97e95515c30e2
parent 324863 10fa130289d70f0adb8ad8379d3454976c922049
child 324865 a770e8c521f7d60fcb6e8d14555b7de282ad1e1e
push id9671
push userraliiev@mozilla.com
push dateMon, 06 Jun 2016 20:27:52 +0000
treeherdermozilla-aurora@cea65ca3d0bd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssebastian
bugs1265708
milestone49.0a1
Bug 1265708 - Post: query topsites metadata by URL without ref too r=sebastian MozReview-Commit-ID: KzbKJjRm4Za
mobile/android/base/java/org/mozilla/gecko/home/TopSitesPanel.java
--- a/mobile/android/base/java/org/mozilla/gecko/home/TopSitesPanel.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/TopSitesPanel.java
@@ -12,18 +12,16 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.EnumSet;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
 import org.mozilla.gecko.GeckoProfile;
 import org.mozilla.gecko.R;
-import org.mozilla.gecko.Tab;
-import org.mozilla.gecko.Tabs;
 import org.mozilla.gecko.Telemetry;
 import org.mozilla.gecko.TelemetryContract;
 import org.mozilla.gecko.db.BrowserContract.Thumbnails;
 import org.mozilla.gecko.db.BrowserContract.TopSites;
 import org.mozilla.gecko.db.BrowserDB;
 import org.mozilla.gecko.favicons.Favicons;
 import org.mozilla.gecko.favicons.OnFaviconLoadedListener;
 import org.mozilla.gecko.gfx.BitmapUtils;
@@ -807,31 +805,41 @@ public class TopSitesPanel extends HomeF
 
         @Override
         public Map<String, ThumbnailInfo> loadInBackground() {
             final Map<String, ThumbnailInfo> thumbnails = new HashMap<String, ThumbnailInfo>();
             if (mUrls == null || mUrls.size() == 0) {
                 return thumbnails;
             }
 
+            // We need to query metadata based on the URL without any refs, hence we create a new
+            // mapping and list of these URLs (we need to preserve the original URL for display purposes)
+            final Map<String, String> queryURLs = new HashMap<>();
+            for (final String pageURL : mUrls) {
+                queryURLs.put(pageURL, StringUtils.stripRef(pageURL));
+            }
+
             // Query the DB for tile images.
             final ContentResolver cr = getContext().getContentResolver();
-            final Map<String, Map<String, Object>> metadata = mDB.getURLMetadata().getForURLs(cr, mUrls, COLUMNS);
+            // Use the stripped URLs for querying the DB
+            final Map<String, Map<String, Object>> metadata = mDB.getURLMetadata().getForURLs(cr, queryURLs.values(), COLUMNS);
 
             // Keep a list of urls that don't have tiles images. We'll use thumbnails for them instead.
             final List<String> thumbnailUrls = new ArrayList<String>();
-            for (String url : mUrls) {
-                ThumbnailInfo info = ThumbnailInfo.fromMetadata(metadata.get(url));
+            for (final String pageURL : mUrls) {
+                final String queryURL = queryURLs.get(pageURL);
+
+                ThumbnailInfo info = ThumbnailInfo.fromMetadata(metadata.get(queryURL));
                 if (info == null) {
                     // If we didn't find metadata, we'll look for a thumbnail for this url.
-                    thumbnailUrls.add(url);
+                    thumbnailUrls.add(pageURL);
                     continue;
                 }
 
-                thumbnails.put(url, info);
+                thumbnails.put(pageURL, info);
             }
 
             if (thumbnailUrls.size() == 0) {
                 return thumbnails;
             }
 
             // Query the DB for tile thumbnails.
             final Cursor cursor = mDB.getThumbnailsForUrls(cr, thumbnailUrls);