OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
[33392] Allow to cache requests in the course of the changeset
Oliver Günther4c575217bb2c
diff --git a/frontend/src/app/modules/fields/changeset/resource-changeset.ts b/frontend/src/app/modules/fields/changeset/resource-changeset.tsindex 6777869c752..0082cd8ddb1 100644--- a/frontend/src/app/modules/fields/changeset/resource-changeset.ts+++ b/frontend/src/app/modules/fields/changeset/resource-changeset.ts@@ -25,6 +25,9 @@ export class ResourceChangeset<T extends HalResource|{ [key:string]:unknown; } =/** Reference and load promise for the current form */protected form$ = input<FormResource>();+ /** Request cache for objects within the changeset for the current form */+ protected cache:{ [key:string]:Promise<unknown> } = {};+/** Flag whether this is currently being saved */public inFlight = false;@@ -94,6 +97,10 @@ export class ResourceChangeset<T extends HalResource|{ [key:string]:unknown; } =.toPromise();}+ /**+ * Cache some promised value in the course of this changeset.+ * Will get cleared automatically by the changeset on destroy/submission+ *//*** Posts to the form with the current changes@@ -106,6 +113,7 @@ export class ResourceChangeset<T extends HalResource|{ [key:string]:unknown; } =.$links.update(payload).then((form:FormResource) => {+ this.cache = {};this.form$.putValue(form);this.setNewDefaults(form);this.push();@@ -223,6 +231,7 @@ export class ResourceChangeset<T extends HalResource|{ [key:string]:unknown; } =public clear() {this.state && this.state.clear();this.changeset.clear();+ this.cache = {};this.form$.clear();}@@ -252,6 +261,18 @@ export class ResourceChangeset<T extends HalResource|{ [key:string]:unknown; } =return this.form$.getValueOr(this.pristineResource).schema;}+ /**+ * Access some promised value+ * that should be cached for the lifetime duration of the form.+ */+ public cacheValue<T>(key:string, request:() => Promise<T>):Promise<T> {+ if (this.cache[key]) {+ return this.cache[key] as Promise<T>;+ }++ return this.cache[key] = request();+ }+protected get minimalPayload() {return { lockVersion: this.pristineResource.lockVersion, _links: {} };}diff --git a/frontend/src/app/modules/fields/edit/field-types/select-edit-field.component.ts b/frontend/src/app/modules/fields/edit/field-types/select-edit-field.component.tsindex 8d502a36d5a..7cc23a7a7cd 100644--- a/frontend/src/app/modules/fields/edit/field-types/select-edit-field.component.ts+++ b/frontend/src/app/modules/fields/edit/field-types/select-edit-field.component.ts@@ -153,7 +153,7 @@ export class SelectEditFieldComponent extends EditFieldComponent implements OnInprotected loadValuesFromBackend(query?:string) {return from(- this.allowedValuesFetch(query)+ this.loadAllowedValues(query)).pipe(tap(collection => {// if it is an unpaginated collection or if we get all possible entries when fetching with a blank@@ -174,7 +174,17 @@ export class SelectEditFieldComponent extends EditFieldComponent implements OnIn);}- protected allowedValuesFetch(query?:string) {+ protected loadAllowedValues(query?:string):Promise<CollectionResource> {+ // Cache the search without any params+ if (!query) {+ const cacheKey = this.schema.allowedValues.$link.href;+ return this.change.cacheValue(cacheKey, this.fetchAllowedValueQuery.bind(this));+ }++ return this.fetchAllowedValueQuery(query);+ }++ protected fetchAllowedValueQuery(query?:string) {return this.schema.allowedValues.$link.$fetch(this.allowedValuesFilter(query)) as Promise<CollectionResource>;}diff --git a/frontend/src/app/modules/fields/edit/field-types/te-work-package-edit-field.component.ts b/frontend/src/app/modules/fields/edit/field-types/te-work-package-edit-field.component.tsindex 67ea126b309..7e26095004a 100644--- a/frontend/src/app/modules/fields/edit/field-types/te-work-package-edit-field.component.ts+++ b/frontend/src/app/modules/fields/edit/field-types/te-work-package-edit-field.component.ts@@ -93,10 +93,10 @@ export class TimeEntryWorkPackageEditFieldComponent extends WorkPackageEditField.map((timeEntry) => timeEntry.workPackage.idFromLink).filter((v, i, a) => a.indexOf(v) === i);- return super.allowedValuesFetch(query);+ return super.loadAllowedValues(query);});} else {- return super.allowedValuesFetch(query);+ return super.loadAllowedValues(query);}}