Browse Source

Prevent repeated requests for failed entity logos

pull/7006/head
AkashNegi1 10 hours ago
parent
commit
351f6dfa12
  1. 10
      libs/ui/src/lib/entity-logo/entity-logo-image-source.service.ts
  2. 2
      libs/ui/src/lib/entity-logo/entity-logo.component.html
  3. 28
      libs/ui/src/lib/entity-logo/entity-logo.component.ts

10
libs/ui/src/lib/entity-logo/entity-logo-image-source.service.ts

@ -7,6 +7,8 @@ import { Injectable } from '@angular/core';
providedIn: 'root' providedIn: 'root'
}) })
export class EntityLogoImageSourceService { export class EntityLogoImageSourceService {
private failedImageSources = new Set<string>();
public getLogoUrlByAssetProfileIdentifier({ public getLogoUrlByAssetProfileIdentifier({
dataSource, dataSource,
symbol symbol
@ -17,4 +19,12 @@ export class EntityLogoImageSourceService {
public getLogoUrlByUrl(url: string) { public getLogoUrlByUrl(url: string) {
return `../api/v1/logo?url=${url}`; return `../api/v1/logo?url=${url}`;
} }
public hasFailed(imageSource: string) {
return this.failedImageSources.has(imageSource);
}
public markAsFailed(imageSource: string) {
this.failedImageSources.add(imageSource);
}
} }

2
libs/ui/src/lib/entity-logo/entity-logo.component.html

@ -1,8 +1,8 @@
@if (src) { @if (src) {
<img <img
onerror="this.style.display = 'none'"
[class.large]="size === 'large'" [class.large]="size === 'large'"
[src]="src" [src]="src"
[title]="tooltip ? tooltip : ''" [title]="tooltip ? tooltip : ''"
(error)="onLogoError()"
/> />
} }

28
libs/ui/src/lib/entity-logo/entity-logo.component.ts

@ -23,7 +23,7 @@ export class GfEntityLogoComponent implements OnChanges {
@Input() tooltip: string; @Input() tooltip: string;
@Input() url: string; @Input() url: string;
public src: string; public src: string | undefined;
public constructor( public constructor(
private readonly imageSourceService: EntityLogoImageSourceService private readonly imageSourceService: EntityLogoImageSourceService
@ -31,12 +31,28 @@ export class GfEntityLogoComponent implements OnChanges {
public ngOnChanges() { public ngOnChanges() {
if (this.dataSource && this.symbol) { if (this.dataSource && this.symbol) {
this.src = this.imageSourceService.getLogoUrlByAssetProfileIdentifier({ const candidateSrc =
dataSource: this.dataSource, this.imageSourceService.getLogoUrlByAssetProfileIdentifier({
symbol: this.symbol dataSource: this.dataSource,
}); symbol: this.symbol
});
this.src = this.imageSourceService.hasFailed(candidateSrc)
? undefined
: candidateSrc;
} else if (this.url) { } else if (this.url) {
this.src = this.imageSourceService.getLogoUrlByUrl(this.url); const candidateSrc = this.imageSourceService.getLogoUrlByUrl(this.url);
this.src = this.imageSourceService.hasFailed(candidateSrc)
? undefined
: candidateSrc;
}
}
public onLogoError() {
if (this.src) {
this.imageSourceService.markAsFailed(this.src);
this.src = undefined;
} }
} }
} }

Loading…
Cancel
Save