Skip to content

Commit b601366

Browse files
committed
Removed debug method and improved performance
1 parent b98ab2d commit b601366

1 file changed

Lines changed: 15 additions & 28 deletions

File tree

src/app/item-page/simple/field-components/creative-commons-license-field/creative-commons-license-field.component.ts

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,17 @@ export class CreativeCommonsLicenseFieldComponent implements OnInit {
108108
* Initialize Creative Commons license information
109109
*/
110110
private initializeCcLicense(): void {
111+
// Cache the metadata URL extraction to avoid repeated calls
112+
const metadataUrl = this.extractUrlFromMetadata();
113+
111114
// Check if item has CC_LICENSE bundle and extract license information
112115
const ccLicenseBundle$ = this.bundleService.findByItemAndName(this.item, CC_CONSTANTS.BUNDLE_NAME);
113-
116+
114117
this.hasCcLicense$ = ccLicenseBundle$.pipe(
115118
map((bundleRD: RemoteData<Bundle>) => {
116119
// Check if CC_LICENSE bundle exists OR if CC license metadata exists
117120
const hasBundleLicense = bundleRD.hasSucceeded && isNotEmpty(bundleRD.payload);
118-
const hasMetadataLicense = isNotEmpty(this.extractUrlFromMetadata());
121+
const hasMetadataLicense = isNotEmpty(metadataUrl);
119122
return hasBundleLicense || hasMetadataLicense;
120123
}),
121124
catchError(() => of(false))
@@ -134,18 +137,18 @@ export class CreativeCommonsLicenseFieldComponent implements OnInit {
134137
const bitstreams = bitstreamsRD.payload;
135138
if (bitstreams.page.length > 0) {
136139
// Look for license URL in bitstream metadata or name
137-
const licenseBitstream = bitstreams.page.find(bitstream =>
138-
bitstream.name.includes('license') ||
140+
const licenseBitstream = bitstreams.page.find(bitstream =>
141+
bitstream.name.includes('license') ||
139142
bitstream.metadata[CC_CONSTANTS.METADATA_FIELDS[0]]?.[0]?.value
140143
);
141-
const url = licenseBitstream?.metadata[CC_CONSTANTS.METADATA_FIELDS[0]]?.[0]?.value ||
142-
this.extractUrlFromMetadata() ||
144+
const url = licenseBitstream?.metadata[CC_CONSTANTS.METADATA_FIELDS[0]]?.[0]?.value ||
145+
metadataUrl ||
143146
'';
144147
return of(url);
145148
}
146149
}
147-
// Fallback to metadata-based detection
148-
return of(this.extractUrlFromMetadata());
150+
// Fallback to cached metadata-based detection
151+
return of(metadataUrl);
149152
}),
150153
catchError(() => of(''))
151154
);
@@ -205,7 +208,7 @@ export class CreativeCommonsLicenseFieldComponent implements OnInit {
205208
*/
206209
getCcIconClass(licenseName: string): string {
207210
const lowerName = licenseName.toLowerCase();
208-
211+
209212
if (CC_CONSTANTS.LICENSE_TYPE_PATTERNS.CC0.some(pattern => lowerName.includes(pattern))) {
210213
return CC_CONSTANTS.ICON_CLASSES.ZERO;
211214
} else if (CC_CONSTANTS.LICENSE_TYPE_PATTERNS.BY_NC_ND.some(pattern => lowerName.includes(pattern))) {
@@ -221,7 +224,7 @@ export class CreativeCommonsLicenseFieldComponent implements OnInit {
221224
} else if (CC_CONSTANTS.LICENSE_TYPE_PATTERNS.BY.some(pattern => lowerName.includes(pattern))) {
222225
return `${CC_CONSTANTS.ICON_CLASSES.BASE} ${CC_CONSTANTS.ICON_CLASSES.BY}`;
223226
}
224-
227+
225228
return CC_CONSTANTS.ICON_CLASSES.BASE;
226229
}
227230

@@ -230,9 +233,9 @@ export class CreativeCommonsLicenseFieldComponent implements OnInit {
230233
*/
231234
getLicenseType(licenseName: string): string {
232235
if (!licenseName) return '';
233-
236+
234237
const name = licenseName.toLowerCase();
235-
238+
236239
if (CC_CONSTANTS.LICENSE_TYPE_PATTERNS.CC0.some(pattern => name.includes(pattern))) {
237240
return CC_CONSTANTS.TEMPLATE_SWITCH_CASES.CC0;
238241
} else if (CC_CONSTANTS.LICENSE_TYPE_PATTERNS.BY_NC_ND.some(pattern => name.includes(pattern))) {
@@ -251,20 +254,4 @@ export class CreativeCommonsLicenseFieldComponent implements OnInit {
251254
return '';
252255
}
253256
}
254-
255-
/**
256-
* Debug helper: Get metadata values for a given field
257-
*/
258-
getMetadataValues(field: string): string {
259-
if (!this.item || !this.item.metadata) {
260-
return CC_CONSTANTS.DEFAULT_MESSAGES.NO_METADATA;
261-
}
262-
263-
const values = this.item.allMetadata(field);
264-
if (values && values.length > 0) {
265-
return values.map(v => v.value).join('; ');
266-
}
267-
268-
return CC_CONSTANTS.DEFAULT_MESSAGES.NO_VALUES;
269-
}
270257
}

0 commit comments

Comments
 (0)