decrease the number of unnecessary rerenders by checking whether the relationship types have changed

This commit is contained in:
Art Lowel
2024-05-09 15:25:37 +02:00
parent 4541788a34
commit a658bf4531
2 changed files with 11 additions and 17 deletions

View File

@@ -347,7 +347,7 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
); );
}), }),
take(1) take(1)
) );
} else { } else {
return EMPTY; return EMPTY;
} }
@@ -355,7 +355,7 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
toArray(), toArray(),
).subscribe({ ).subscribe({
complete: () => { complete: () => {
this.editItemRelationshipsService.submit(this.item, this.url) this.editItemRelationshipsService.submit(this.item, this.url);
this.submitModal.emit(); this.submitModal.emit();
} }
}); });

View File

@@ -1,14 +1,13 @@
import { ChangeDetectorRef, Component } from '@angular/core'; import { ChangeDetectorRef, Component } from '@angular/core';
import { Item } from '../../../core/shared/item.model';
import { import {
DeleteRelationship, map,
RelationshipIdentifiable, distinctUntilChanged
} from '../../../core/data/object-updates/object-updates.reducer'; } from 'rxjs/operators';
import { map, switchMap, take, concatMap, toArray, tap } from 'rxjs/operators';
import { import {
combineLatest as observableCombineLatest,
Observable, Observable,
BehaviorSubject, EMPTY BehaviorSubject
} from 'rxjs'; } from 'rxjs';
import { followLink } from '../../../shared/utils/follow-link-config.model'; import { followLink } from '../../../shared/utils/follow-link-config.model';
import { AbstractItemUpdateComponent } from '../abstract-item-update/abstract-item-update.component'; import { AbstractItemUpdateComponent } from '../abstract-item-update/abstract-item-update.component';
@@ -18,23 +17,17 @@ import { ActivatedRoute, Router } from '@angular/router';
import { NotificationsService } from '../../../shared/notifications/notifications.service'; import { NotificationsService } from '../../../shared/notifications/notifications.service';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { RelationshipDataService } from '../../../core/data/relationship-data.service'; import { RelationshipDataService } from '../../../core/data/relationship-data.service';
import { RemoteData } from '../../../core/data/remote-data';
import { ObjectCacheService } from '../../../core/cache/object-cache.service'; import { ObjectCacheService } from '../../../core/cache/object-cache.service';
import { getFirstSucceededRemoteData, getRemoteDataPayload } from '../../../core/shared/operators'; import { getFirstSucceededRemoteData, getRemoteDataPayload } from '../../../core/shared/operators';
import { RequestService } from '../../../core/data/request.service'; import { RequestService } from '../../../core/data/request.service';
import { RelationshipType } from '../../../core/shared/item-relationships/relationship-type.model'; import { RelationshipType } from '../../../core/shared/item-relationships/relationship-type.model';
import { ItemType } from '../../../core/shared/item-relationships/item-type.model'; import { ItemType } from '../../../core/shared/item-relationships/item-type.model';
import { EntityTypeDataService } from '../../../core/data/entity-type-data.service'; import { EntityTypeDataService } from '../../../core/data/entity-type-data.service';
import { Relationship } from '../../../core/shared/item-relationships/relationship.model';
import { NoContent } from '../../../core/shared/NoContent.model';
import { hasValue } from '../../../shared/empty.util';
import { FieldUpdate } from '../../../core/data/object-updates/field-update.model';
import { FieldUpdates } from '../../../core/data/object-updates/field-updates.model';
import { FieldChangeType } from '../../../core/data/object-updates/field-change-type.model';
import { RelationshipTypeDataService } from '../../../core/data/relationship-type-data.service'; import { RelationshipTypeDataService } from '../../../core/data/relationship-type-data.service';
import { PaginatedList } from '../../../core/data/paginated-list.model'; import { PaginatedList } from '../../../core/data/paginated-list.model';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { EditItemRelationshipsService } from './edit-item-relationships.service'; import { EditItemRelationshipsService } from './edit-item-relationships.service';
import { compareArraysUsingIds } from '../../simple/item-types/shared/item-relationships-utils';
@Component({ @Component({
selector: 'ds-item-relationships', selector: 'ds-item-relationships',
@@ -89,7 +82,8 @@ export class ItemRelationshipsComponent extends AbstractItemUpdateComponent {
if (label !== undefined) { if (label !== undefined) {
this.relationshipTypes$ = this.relationshipTypeService.searchByEntityType(label, true, true, ...this.getRelationshipTypeFollowLinks()) this.relationshipTypes$ = this.relationshipTypeService.searchByEntityType(label, true, true, ...this.getRelationshipTypeFollowLinks())
.pipe( .pipe(
map((relationshipTypes: PaginatedList<RelationshipType>) => relationshipTypes.page) map((relationshipTypes: PaginatedList<RelationshipType>) => relationshipTypes.page),
distinctUntilChanged(compareArraysUsingIds())
); );
this.entityTypeService.getEntityTypeByLabel(label).pipe( this.entityTypeService.getEntityTypeByLabel(label).pipe(