Commit 6fe22c80 authored by Sophie Chang's avatar Sophie Chang Committed by Commit Bot

Add a null hint cache entry for hosts if there is no persistent store

This should hopefully help reduce the number of requests when there is
no persistent store available so we don't keep fetching for the host if
we know that there was no hint available for it from the server during
the session.

Bug: 1112500
Change-Id: I6b7514bba0a96fa13866b55287f091ef4201a3f4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2364081Reviewed-by: default avatarMichael Crouse <mcrouse@chromium.org>
Commit-Queue: Sophie Chang <sophiechang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#799771}
parent d49e7b56
...@@ -1135,7 +1135,8 @@ OptimizationGuideHintsManager::CanApplyOptimization( ...@@ -1135,7 +1135,8 @@ OptimizationGuideHintsManager::CanApplyOptimization(
// If we do not have a hint already loaded and we do not have one in the // If we do not have a hint already loaded and we do not have one in the
// cache, we do not know what to do with the URL so just return. // cache, we do not know what to do with the URL so just return.
// Otherwise, we do have information, but we just do not know it yet. // Otherwise, we do have information, but we just do not know it yet.
if (hint_cache_->HasHint(host)) { if (optimization_guide::features::ShouldPersistHintsToDisk() &&
hint_cache_->HasHint(host)) {
return optimization_guide::OptimizationTypeDecision:: return optimization_guide::OptimizationTypeDecision::
kHadHintButNotLoadedInTime; kHadHintButNotLoadedInTime;
} }
......
...@@ -88,6 +88,16 @@ void HintCache::UpdateFetchedHints( ...@@ -88,6 +88,16 @@ void HintCache::UpdateFetchedHints(
url_keyed_hint_cache_.Put(url.spec(), nullptr); url_keyed_hint_cache_.Put(url.spec(), nullptr);
} }
if (!optimization_guide_store_) {
// If there's not a store, add a null entry for each of the hosts that we
// didn't have already, so we don't refetch if we didn't get a hint back
// for it.
for (const std::string& host : hosts_fetched) {
if (host_keyed_cache_.Peek(host) == host_keyed_cache_.end())
host_keyed_cache_.Put(host, nullptr);
}
}
ProcessAndCacheHints(get_hints_response.get()->mutable_hints(), ProcessAndCacheHints(get_hints_response.get()->mutable_hints(),
fetched_hints_update_data.get()); fetched_hints_update_data.get());
...@@ -135,7 +145,7 @@ bool HintCache::HasHint(const std::string& host) { ...@@ -135,7 +145,7 @@ bool HintCache::HasHint(const std::string& host) {
// The hint for |host| was requested but no hint was returned. // The hint for |host| was requested but no hint was returned.
if (!hint_it->second) if (!hint_it->second)
return false; return true;
MemoryHint* hint = hint_it->second.get(); MemoryHint* hint = hint_it->second.get();
if (!hint->expiry_time() || *hint->expiry_time() > clock_->Now()) if (!hint->expiry_time() || *hint->expiry_time() > clock_->Now())
......
...@@ -602,7 +602,8 @@ TEST_P(HintCacheTest, ParseEmptyFetchedHints) { ...@@ -602,7 +602,8 @@ TEST_P(HintCacheTest, ParseEmptyFetchedHints) {
std::unique_ptr<proto::GetHintsResponse> get_hints_response = std::unique_ptr<proto::GetHintsResponse> get_hints_response =
std::make_unique<proto::GetHintsResponse>(); std::make_unique<proto::GetHintsResponse>();
UpdateFetchedHintsAndWait(std::move(get_hints_response), stored_time, {}, {}); UpdateFetchedHintsAndWait(std::move(get_hints_response), stored_time,
{"host.domain.org"}, {});
// Empty Fetched Hints causes the metadata entry to be updated if store is // Empty Fetched Hints causes the metadata entry to be updated if store is
// available. // available.
EXPECT_TRUE(are_fetched_hints_updated()); EXPECT_TRUE(are_fetched_hints_updated());
...@@ -611,6 +612,9 @@ TEST_P(HintCacheTest, ParseEmptyFetchedHints) { ...@@ -611,6 +612,9 @@ TEST_P(HintCacheTest, ParseEmptyFetchedHints) {
EXPECT_EQ(hint_cache()->GetFetchedHintsUpdateTime(), stored_time); EXPECT_EQ(hint_cache()->GetFetchedHintsUpdateTime(), stored_time);
} else { } else {
EXPECT_EQ(hint_cache()->GetFetchedHintsUpdateTime(), base::Time()); EXPECT_EQ(hint_cache()->GetFetchedHintsUpdateTime(), base::Time());
// Fetched hosts should still have an entry despite not getting a hint back
// for it.
EXPECT_TRUE(hint_cache()->HasHint("host.domain.org"));
} }
} }
......
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