Skip to content

Commit

Permalink
address feedback and cleanup
Browse files Browse the repository at this point in the history
This commit addresses review feedback and cleansup the code in the
following way:
- rename `updateExtensions` to `addExtensions` which is more appropriate
- remove unnecessary `async`
- fire parallel requests instead of serializing them

Signed-off-by: Vlad Arama <vlad.arama@ericsson.com>
  • Loading branch information
vladarama committed Nov 27, 2023
1 parent da67994 commit 6d1f700
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions packages/vsx-registry/src/browser/vsx-extensions-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,8 @@ export class VSXExtensionsModel {
});
}

protected async doUpdateSearchResult(param: VSXSearchOptions, token: CancellationToken): Promise<void> {
protected doUpdateSearchResult(param: VSXSearchOptions, token: CancellationToken): Promise<void> {
return this.doChange(async () => {
const fetchPromisesArray: Promise<void>[] = [];
this._searchResult = new Set<string>();
if (!param.query) {
return;
Expand All @@ -233,23 +232,26 @@ export class VSXExtensionsModel {
continue;
}
if (this.preferences.get('extensions.onlyShowVerifiedExtensions')) {
const verified = await this.fetchVerifiedStatus(id, client, allVersions);
this.updateExtensions(data, id, allVersions, !!verified);
this.fetchVerifiedStatus(id, client, allVersions).then(verified => {
this.doChange(() => {
this.addExtensions(data, id, allVersions, !!verified);
return Promise.resolve();
});
});
} else {
this.updateExtensions(data, id, allVersions);
const fetchPromise = this.fetchVerifiedStatus(id, client, allVersions).then(verified => {
let extension = this.getExtension(id);
extension = this.setExtension(id);
extension.update(Object.assign({
verified: verified
}));
this.addExtensions(data, id, allVersions);
this.fetchVerifiedStatus(id, client, allVersions).then(verified => {
this.doChange(() => {
let extension = this.getExtension(id);
extension = this.setExtension(id);
extension.update(Object.assign({
verified: verified
}));
return Promise.resolve();
});
});
fetchPromisesArray.push(fetchPromise);
}
}
Promise.all(fetchPromisesArray).then(async () => this.doChange(async () => {
await this.initialized;
}));
}, token);
}

Expand All @@ -262,7 +264,7 @@ export class VSXExtensionsModel {
return verified;
}

protected updateExtensions(data: VSXSearchEntry, id: string, allVersions: VSXAllVersions, verified?: boolean): void {
protected addExtensions(data: VSXSearchEntry, id: string, allVersions: VSXAllVersions, verified?: boolean): void {
if (!this.preferences.get('extensions.onlyShowVerifiedExtensions') || verified) {
const extension = this.setExtension(id);
extension.update(Object.assign(data, {
Expand Down

0 comments on commit 6d1f700

Please sign in to comment.