Commit cdef2348 authored by Jonathan Freed's avatar Jonathan Freed Committed by Commit Bot

[Explore Sites] Fixing SQL query to gather icons for category tiles.

Previously, the SQL query included site icons that were NULL or empty,
resulting in category tiles often having less than 4 site icons present.
This fix skips the empty icons, and grabs the next non-empty ones.

Change-Id: I314c78f1797769e598640d06162811e1672c2449
Reviewed-on: https://chromium-review.googlesource.com/c/1279155Reviewed-by: default avatarPeter Williamson <petewil@chromium.org>
Commit-Queue: Jonathan Freed <freedjm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#599347}
parent 08481ae5
......@@ -16,7 +16,8 @@ namespace {
const char kSelectCategoryImagesSql[] = R"(SELECT favicon
FROM sites
LEFT JOIN site_blacklist ON (sites.url = site_blacklist.url)
WHERE category_id = ? AND NOT removed AND site_blacklist.url IS NULL
WHERE category_id = ? AND LENGTH(favicon) > 0 AND NOT removed
AND site_blacklist.url IS NULL
LIMIT ?;)";
const char kSelectSiteImageSql[] =
......
......@@ -175,4 +175,25 @@ VALUES
EXPECT_EQ(4U, last_result.size());
}
TEST_F(ExploreSitesGetImagesTaskTest, SkipMissingFavicons) {
PopulateTestingCatalog();
ExecuteSync(base::BindLambdaForTesting([&](sql::Database* db) {
sql::Statement insert(db->GetUniqueStatement(R"(
INSERT INTO sites
(site_id, url, category_id, title, favicon)
VALUES
(5, "https://www.example.com/5", 3, "example_5", NULL),
(6, "https://www.example.com/6", 3, "example_6", ""),
(7, "https://www.example.com/7", 3, "example_7", "bytes7");
)"));
return insert.Run();
}));
GetImagesTask task(store(), 3, 3, StoreResult());
RunTask(&task);
EXPECT_EQ(3U, last_result.size());
std::vector<uint8_t>& result3 = *last_result[2];
EXPECT_EQ("bytes7", std::string(result3.begin(), result3.end()));
}
} // namespace explore_sites
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment