Bug 1629588 - Ensure we don't setup a new provider if one already exists. r=gvn

Differential Revision: https://phabricator.services.mozilla.com/D70890
This commit is contained in:
Scott 2020-04-20 18:12:37 +00:00
Родитель 6a36b46f0d
Коммит d91ab8e98e
2 изменённых файлов: 35 добавлений и 0 удалений

Просмотреть файл

@ -57,6 +57,15 @@ this.RecommendationProviderSwitcher = class RecommendationProviderSwitcher {
setAffinityProvider(...args) {
const { affinityProviderV2 } = this;
if (affinityProviderV2 && affinityProviderV2.modelKeys) {
// A v2 provider is already set. This can happen when new stories come in
// and we need to update their scores.
// We can use the existing one, a fresh one is created after startup.
// Using the existing one might be a bit out of date,
// but it's fine for now. We can rely on restarts for updates.
// See bug 1629931 for improvements to this.
if (this.affinityProvider) {
return;
}
// At this point we've determined we can successfully create a v2 personalization provider.
this.affinityProvider = new PersonalityProvider(...args, {
modelKeys: affinityProviderV2.modelKeys,

Просмотреть файл

@ -31,6 +31,7 @@ describe("RecommendationProviderSwitcher", () => {
assert.equal(feed.affinityProvider.modelKeys, undefined);
feed.affinityProvider = null;
feed.affinityProviderV2 = {
modelKeys: "1234",
};
@ -45,6 +46,31 @@ describe("RecommendationProviderSwitcher", () => {
assert.equal(feed.affinityProvider.modelKeys, "1234");
});
it("should use old provider", async () => {
feed.setAffinityProvider(
undefined,
undefined,
undefined,
undefined,
undefined
);
assert.equal(feed.affinityProvider.modelKeys, undefined);
feed.affinityProviderV2 = {
modelKeys: "1234",
};
feed.setAffinityProvider(
undefined,
undefined,
undefined,
undefined,
undefined
);
assert.equal(feed.affinityProvider.modelKeys, undefined);
});
});
describe("#init", () => {