Skip to content
This repository has been archived by the owner on Feb 29, 2020. It is now read-only.

Commit

Permalink
Bug 1479458 - Fixing broadcast of updated data from cache.
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottDowne committed Aug 13, 2018
1 parent e7cf961 commit a679625
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
7 changes: 1 addition & 6 deletions lib/TopStoriesFeed.jsm
Expand Up @@ -40,8 +40,6 @@ this.TopStoriesFeed = class TopStoriesFeed {
try {
const {options} = SectionsManager.sections.get(SECTION_ID);
const apiKey = this.getApiKeyFromPref(options.api_key_pref);
// Set this to true if we're not loading from cache.
let shouldBroadcast = false;
this.stories_endpoint = this.produceFinalEndpointUrl(options.stories_endpoint, apiKey);
this.topics_endpoint = this.produceFinalEndpointUrl(options.topics_endpoint, apiKey);
this.read_more_endpoint = options.read_more_endpoint;
Expand All @@ -57,17 +55,14 @@ this.TopStoriesFeed = class TopStoriesFeed {
// Cache is used for new page loads, which shouldn't have changed data.
// If we have changed data, cache should be cleared,
// and last updated should be 0, and we can fetch.
// Think there is a bug here.
await this.loadCachedData();
if (this.storiesLastUpdated === 0) {
shouldBroadcast = true;
await this.fetchStories();
}
if (this.topicsLastUpdated === 0) {
shouldBroadcast = true;
await this.fetchTopics();
}
this.doContentUpdate(shouldBroadcast);
this.doContentUpdate(true);
this.storiesLoaded = true;

// This is filtered so an update function can return true to retry on the next run
Expand Down
11 changes: 11 additions & 0 deletions test/unit/lib/TopStoriesFeed.test.js
Expand Up @@ -1007,6 +1007,17 @@ describe("Top Stories Feed", () => {
await instance.loadCachedData();
assert.notCalled(sectionsManagerStub.updateSection);
});
it("should broadcast in doContentUpdate when updating from cache", async () => {
sectionsManagerStub.sections.set("topstories", {options: {stories_referrer: "referrer"}});
globals.set("NewTabUtils", {blockedLinks: {isBlocked: () => {}}});
const stories = {"recommendations": [{}]};
const topics = {"topics": [{}]};
sinon.spy(instance, "doContentUpdate");
instance.cache.get = () => ({stories, topics});
await instance.onInit();
assert.calledOnce(instance.doContentUpdate);
assert.calledWith(instance.doContentUpdate, true);
});
it("should initialize user domain affinity provider from cache if personalization is preffed on", async () => {
const domainAffinities = {
"parameterSets": {
Expand Down

0 comments on commit a679625

Please sign in to comment.