Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seed shuffle of recommended extensions per session #53505

Merged
merged 2 commits into from
Jul 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 13 additions & 8 deletions src/vs/base/common/arrays.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,14 +470,19 @@ export function arrayInsert<T>(target: T[], insertIndex: number, insertArr: T[])
* Uses Fisher-Yates shuffle to shuffle the given array
* @param array
*/
export function shuffle<T>(array: T[]): void {
var i = 0
, j = 0
, temp = null;

for (i = array.length - 1; i > 0; i -= 1) {
j = Math.floor(Math.random() * (i + 1));
temp = array[i];
export function shuffle<T>(array: T[], seed?: number): void {
// Seeded random number generator in JS. Modified from:
// https://stackoverflow.com/questions/521295/seeding-the-random-number-generator-in-javascript
const random = () => {
var x = Math.sin(seed++) * 179426549; // throw away most significant digits and reduce any potential bias
return x - Math.floor(x);
};

const rand = typeof seed === 'number' ? random : Math.random;

for (let i = array.length - 1; i > 0; i -= 1) {
let j = Math.floor(rand() * (i + 1));
let temp = array[i];
array[i] = array[j];
array[j] = temp;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export class ExtensionTipsService extends Disposable implements IExtensionTipsSe

private readonly _onRecommendationChange: Emitter<RecommendationChangeNotification> = new Emitter<RecommendationChangeNotification>();
onRecommendationChange: Event<RecommendationChangeNotification> = this._onRecommendationChange.event;
private sessionSeed: number;

constructor(
@IExtensionGalleryService private readonly _galleryService: IExtensionGalleryService,
Expand All @@ -108,7 +109,6 @@ export class ExtensionTipsService extends Disposable implements IExtensionTipsSe
) {
super();


if (!this.isEnabled()) {
return;
}
Expand All @@ -117,6 +117,8 @@ export class ExtensionTipsService extends Disposable implements IExtensionTipsSe
this._extensionsRecommendationsUrl = product.extensionsGallery.recommendationsUrl;
}

this.sessionSeed = +new Date();

let globallyIgnored = <string[]>JSON.parse(this.storageService.get('extensionsAssistant/ignored_recommendations', StorageScope.GLOBAL, '[]'));
this._globallyIgnoredRecommendations = globallyIgnored.map(id => id.toLowerCase());

Expand Down Expand Up @@ -405,7 +407,7 @@ export class ExtensionTipsService extends Disposable implements IExtensionTipsSe
...this._dynamicWorkspaceRecommendations,
...Object.keys(this._experimentalRecommendations),
]).filter(extensionId => this.isExtensionAllowedToBeRecommended(extensionId));
shuffle(others);
shuffle(others, this.sessionSeed);
return others.map(extensionId => {
const sources: ExtensionRecommendationSource[] = [];
if (this._exeBasedRecommendations[extensionId]) {
Expand Down