From ecc0de9a4c5fdd9c7027d0205c661864b44873bb Mon Sep 17 00:00:00 2001 From: William Welling Date: Tue, 30 Jan 2024 10:21:20 -0600 Subject: [PATCH 1/3] Do not patch section before proxy license file upload --- .../sections/license/section-license.component.ts | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/themes/tamu/app/submission/sections/license/section-license.component.ts b/src/themes/tamu/app/submission/sections/license/section-license.component.ts index a1d32e34cc8..61fb5be6bbf 100644 --- a/src/themes/tamu/app/submission/sections/license/section-license.component.ts +++ b/src/themes/tamu/app/submission/sections/license/section-license.component.ts @@ -2,7 +2,7 @@ import { ChangeDetectorRef, Component, ElementRef, Inject, ViewChild } from '@an import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; import { DynamicCheckboxModel, DynamicFormLayout, DynamicRadioGroupModel, MATCH_DISABLED } from '@ng-dynamic-forms/core'; import { TranslateService } from '@ngx-translate/core'; -import { BehaviorSubject, Observable, Subscription } from 'rxjs'; +import { BehaviorSubject, Observable, of } from 'rxjs'; import { distinctUntilChanged, filter, map, switchMap, take, tap } from 'rxjs/operators'; import { AuthService } from '../../../../../../app/core/auth/auth.service'; @@ -16,7 +16,6 @@ import { HALEndpointService } from '../../../../../../app/core/shared/hal-endpoi import { License } from '../../../../../../app/core/shared/license.model'; import { WorkspaceitemSectionLicenseObject } from '../../../../../../app/core/submission/models/workspaceitem-section-license.model'; import { WorkspaceItem } from '../../../../../../app/core/submission/models/workspaceitem.model'; -import { SubmissionJsonPatchOperationsService } from '../../../../../../app/core/submission/submission-json-patch-operations.service'; import { normalizeSectionData } from '../../../../../../app/core/submission/submission-response-parsing.service'; import { isNotEmpty, isNotUndefined } from '../../../../../../app/shared/empty.util'; import { FormBuilderService } from '../../../../../../app/shared/form/builder/form-builder.service'; @@ -111,7 +110,6 @@ export class SubmissionSectionLicenseComponent extends BaseComponent { private halEndpointService: HALEndpointService, private modalService: NgbModal, private notificationsService: NotificationsService, - private operationsService: SubmissionJsonPatchOperationsService, private sectionUploadService: SectionUploadService, protected changeDetectorRef: ChangeDetectorRef, protected collectionDataService: CollectionDataService, @@ -282,13 +280,7 @@ export class SubmissionSectionLicenseComponent extends BaseComponent { * @returns empty observable */ public onBeforeUpload = () => { - const sub: Subscription = this.operationsService.jsonPatchByResourceType( - this.submissionService.getSubmissionObjectLinkName(), - this.submissionId, - 'sections') - .subscribe(); - this.subs.push(sub); - return sub; + return of(); }; /** From b29401a7a35e3818ceb4ac1f7e2277980ab8c027 Mon Sep 17 00:00:00 2001 From: William Welling Date: Fri, 26 Jan 2024 15:56:35 -0600 Subject: [PATCH 2/3] Dedupe patch operations by op and path --- .../json-patch-operations.reducer.ts | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/app/core/json-patch/json-patch-operations.reducer.ts b/src/app/core/json-patch/json-patch-operations.reducer.ts index 5e00027edb9..86edd339e8f 100644 --- a/src/app/core/json-patch/json-patch-operations.reducer.ts +++ b/src/app/core/json-patch/json-patch-operations.reducer.ts @@ -351,7 +351,28 @@ function addOperationToList(body: JsonPatchOperationObject[], actionType, target newBody.push(makeOperationEntry({ op: JsonPatchOperationType.move, from: fromPath, path: targetPath })); break; } - return newBody; + return dedupeOperationEntries(newBody); +} + +/** + * Dedupe operation entries by op and path. This prevents processing unnecessary patches in a single PATCH request. + * + * @param body JSON patch operation object entries + * @returns deduped JSON patch operation object entries + */ +function dedupeOperationEntries(body: JsonPatchOperationObject[]): JsonPatchOperationObject[] { + const ops = new Map(); + for (let i = body.length - 1; i >= 0; i--) { + const patch = body[i].operation; + const key = `${patch.op}-${patch.path}`; + if (!ops.has(key)) { + ops.set(key, patch); + } else { + body.splice(i, 1); + } + } + + return body; } function makeOperationEntry(operation) { From ff029983b4135ec28481bcfc4171ca25b08fd56a Mon Sep 17 00:00:00 2001 From: William Welling Date: Tue, 30 Jan 2024 10:26:12 -0600 Subject: [PATCH 3/3] Add TAMU customization comment --- src/app/core/json-patch/json-patch-operations.reducer.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/app/core/json-patch/json-patch-operations.reducer.ts b/src/app/core/json-patch/json-patch-operations.reducer.ts index 86edd339e8f..5f7f46dfe66 100644 --- a/src/app/core/json-patch/json-patch-operations.reducer.ts +++ b/src/app/core/json-patch/json-patch-operations.reducer.ts @@ -355,6 +355,7 @@ function addOperationToList(body: JsonPatchOperationObject[], actionType, target } /** + * TAMU Customization * Dedupe operation entries by op and path. This prevents processing unnecessary patches in a single PATCH request. * * @param body JSON patch operation object entries