Skip to content

Commit fd5de72

Browse files
madsrasmusseniOvergaardAndyButland
authored
Feature: add client runtime cache for all item endpoints (#19960)
* extend controller base * extend controller base * add package for management api * add signalr as external package * connect to server event hub * do no act on undefined * add event subject * correct alias * export token * add helper methods * cache server responses * fix import * use helpers * add detail request manager * implement for document type * implement for data type * add method for update * add support for create method * align code * Update detail-request.manager.ts * move explicit naming * move into folder * collect server code in folder * add implementation for data type request manager * implement for document type * only cache when we have connection to the server events * update * fix imports * introduce item cache * call trough get items controller * remove log * add unit tests for item cache * Create cache.test.ts * use sync method to lookup data type item * use correct alias * remove unused code * data type item cache * add client document type item cache * add client cache for dictionary items * add media item client cache * add client cache for media type item * add client cache for member and member type items * add member group item cache * split detail cache invalidation from request manager * introduce item cache invalidation manager * remove arg * add data type item cache manager * add memeber group item cache invalidation manager * remove unused * invalidate documents when document types changes * align naming * add method to get unique * add dictionary item cache manager * use server model instead of mapping * call method * update args * update document type item cache invalidation * add cache invalidation for member items * update * update * update * add item caching for languages * add template item cache * cache stylesheet items * add caching for script items * cache partial view items * cache user items * cache user group items * add document blueprint item cache * Removed readonly Signs property to re-align client models. * Regenerate client types. * Applied changes from code review. * cache static file items * add webhook item cache * update mocks with signs data * update mocks * fix lint error * fix eslint errors --------- Co-authored-by: Jacob Overgaard <[email protected]> Co-authored-by: Andy Butland <[email protected]>
1 parent 6f51a79 commit fd5de72

File tree

106 files changed

+1085
-187
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+1085
-187
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import { UmbManagementApiDataTypeDetailDataCacheInvalidationManager } from './repository/detail/server-data-source/data-type-detail.server.cache-invalidation.manager.js';
2+
import { UmbManagementApiDataTypeItemDataCacheInvalidationManager } from './repository/item/data-type-item.server.cache-invalidation.manager.js';
23
import type { UmbEntryPointOnInit, UmbEntryPointOnUnload } from '@umbraco-cms/backoffice/extension-api';
34

45
let detailDataCacheInvalidationManager: UmbManagementApiDataTypeDetailDataCacheInvalidationManager | undefined;
6+
let itemDataCacheInvalidationManager: UmbManagementApiDataTypeItemDataCacheInvalidationManager | undefined;
57

68
export const onInit: UmbEntryPointOnInit = (host) => {
79
detailDataCacheInvalidationManager = new UmbManagementApiDataTypeDetailDataCacheInvalidationManager(host);
10+
itemDataCacheInvalidationManager = new UmbManagementApiDataTypeItemDataCacheInvalidationManager(host);
811
};
912

1013
export const onUnload: UmbEntryPointOnUnload = () => {
1114
detailDataCacheInvalidationManager?.destroy();
15+
itemDataCacheInvalidationManager?.destroy();
1216
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { dataTypeItemCache } from './data-type-item.server.cache.js';
2+
import { UmbManagementApiItemDataCacheInvalidationManager } from '@umbraco-cms/backoffice/management-api';
3+
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
4+
import type { DataTypeItemResponseModel } from '@umbraco-cms/backoffice/external/backend-api';
5+
6+
export class UmbManagementApiDataTypeItemDataCacheInvalidationManager extends UmbManagementApiItemDataCacheInvalidationManager<DataTypeItemResponseModel> {
7+
constructor(host: UmbControllerHost) {
8+
super(host, {
9+
dataCache: dataTypeItemCache,
10+
eventSources: ['Umbraco:CMS:DataType'],
11+
});
12+
}
13+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import type { DataTypeItemResponseModel } from '@umbraco-cms/backoffice/external/backend-api';
2+
import { UmbManagementApiItemDataCache } from '@umbraco-cms/backoffice/management-api';
3+
4+
const dataTypeItemCache = new UmbManagementApiItemDataCache<DataTypeItemResponseModel>();
5+
6+
export { dataTypeItemCache };

src/Umbraco.Web.UI.Client/src/packages/data-type/repository/item/data-type-item.server.data-source.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { UMB_DATA_TYPE_ENTITY_TYPE } from '../../entity.js';
22
import type { UmbDataTypeItemModel } from './types.js';
3+
import { UmbManagementApiDataTypeItemDataRequestManager } from './data-type-item.server.request-manager.js';
34
import { UmbItemServerDataSourceBase } from '@umbraco-cms/backoffice/repository';
45
import type { DataTypeItemResponseModel } from '@umbraco-cms/backoffice/external/backend-api';
5-
import { DataTypeService } from '@umbraco-cms/backoffice/external/backend-api';
66
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
77
import { umbExtensionsRegistry } from '@umbraco-cms/backoffice/extension-registry';
88
import type { ManifestPropertyEditorUi } from '@umbraco-cms/backoffice/property-editor';
9-
import { UmbItemDataApiGetRequestController } from '@umbraco-cms/backoffice/entity-item';
109

1110
let manifestPropertyEditorUis: Array<ManifestPropertyEditorUi> = [];
1211

@@ -19,12 +18,13 @@ export class UmbDataTypeItemServerDataSource extends UmbItemServerDataSourceBase
1918
DataTypeItemResponseModel,
2019
UmbDataTypeItemModel
2120
> {
21+
#itemRequestManager = new UmbManagementApiDataTypeItemDataRequestManager(this);
22+
2223
/**
2324
* Creates an instance of UmbDataTypeItemServerDataSource.
2425
* @param {UmbControllerHost} host - The controller host for this controller to be appended to
2526
* @memberof UmbDataTypeItemServerDataSource
2627
*/
27-
2828
constructor(host: UmbControllerHost) {
2929
super(host, {
3030
mapper,
@@ -41,13 +41,7 @@ export class UmbDataTypeItemServerDataSource extends UmbItemServerDataSourceBase
4141
override async getItems(uniques: Array<string>) {
4242
if (!uniques) throw new Error('Uniques are missing');
4343

44-
const itemRequestManager = new UmbItemDataApiGetRequestController(this, {
45-
// eslint-disable-next-line local-rules/no-direct-api-import
46-
api: (args) => DataTypeService.getItemDataType({ query: { id: args.uniques } }),
47-
uniques,
48-
});
49-
50-
const { data, error } = await itemRequestManager.request();
44+
const { data, error } = await this.#itemRequestManager.getItems(uniques);
5145

5246
return { data: this._getMappedItems(data), error };
5347
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* eslint-disable local-rules/no-direct-api-import */
2+
import { dataTypeItemCache } from './data-type-item.server.cache.js';
3+
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
4+
import { DataTypeService, type DataTypeItemResponseModel } from '@umbraco-cms/backoffice/external/backend-api';
5+
import { UmbManagementApiItemDataRequestManager } from '@umbraco-cms/backoffice/management-api';
6+
7+
export class UmbManagementApiDataTypeItemDataRequestManager extends UmbManagementApiItemDataRequestManager<DataTypeItemResponseModel> {
8+
constructor(host: UmbControllerHost) {
9+
super(host, {
10+
getItems: (ids: Array<string>) => DataTypeService.getItemDataType({ query: { id: ids } }),
11+
dataCache: dataTypeItemCache,
12+
getUniqueMethod: (item) => item.id,
13+
});
14+
}
15+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { UmbManagementApiDictionaryItemDataCacheInvalidationManager } from './repository/item/dictionary-item.server.cache-invalidation.manager.js';
2+
import type { UmbEntryPointOnInit, UmbEntryPointOnUnload } from '@umbraco-cms/backoffice/extension-api';
3+
4+
let itemDataCacheInvalidationManager: UmbManagementApiDictionaryItemDataCacheInvalidationManager | undefined;
5+
6+
export const onInit: UmbEntryPointOnInit = (host) => {
7+
itemDataCacheInvalidationManager = new UmbManagementApiDictionaryItemDataCacheInvalidationManager(host);
8+
};
9+
10+
export const onUnload: UmbEntryPointOnUnload = () => {
11+
itemDataCacheInvalidationManager?.destroy();
12+
};

src/Umbraco.Web.UI.Client/src/packages/dictionary/manifests.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,10 @@ export const manifests: Array<UmbExtensionManifest> = [
1616
...searchManifests,
1717
...treeManifests,
1818
...workspaceManifests,
19+
{
20+
name: 'Dictionary Backoffice Entry Point',
21+
alias: 'Umb.EntryPoint.Dictionary',
22+
type: 'backofficeEntryPoint',
23+
js: () => import('./entry-point.js'),
24+
},
1925
];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { dictionaryItemCache } from './dictionary-item.server.cache.js';
2+
import { UmbManagementApiItemDataCacheInvalidationManager } from '@umbraco-cms/backoffice/management-api';
3+
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
4+
import type { DictionaryItemItemResponseModel } from '@umbraco-cms/backoffice/external/backend-api';
5+
6+
export class UmbManagementApiDictionaryItemDataCacheInvalidationManager extends UmbManagementApiItemDataCacheInvalidationManager<DictionaryItemItemResponseModel> {
7+
constructor(host: UmbControllerHost) {
8+
super(host, {
9+
dataCache: dictionaryItemCache,
10+
eventSources: ['Umbraco:CMS:DictionaryItem'],
11+
});
12+
}
13+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import type { DictionaryItemItemResponseModel } from '@umbraco-cms/backoffice/external/backend-api';
2+
import { UmbManagementApiItemDataCache } from '@umbraco-cms/backoffice/management-api';
3+
4+
const dictionaryItemCache = new UmbManagementApiItemDataCache<DictionaryItemItemResponseModel>();
5+
6+
export { dictionaryItemCache };

src/Umbraco.Web.UI.Client/src/packages/dictionary/repository/item/dictionary-item.server.data-source.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import { UMB_DICTIONARY_ENTITY_TYPE } from '../../entity.js';
22
import type { UmbDictionaryItemModel } from './types.js';
3+
import { UmbManagementApiDictionaryItemDataRequestManager } from './dictionary-item.server.request-manager.js';
34
import { UmbItemServerDataSourceBase } from '@umbraco-cms/backoffice/repository';
45
import type { DictionaryItemItemResponseModel } from '@umbraco-cms/backoffice/external/backend-api';
5-
import { DictionaryService } from '@umbraco-cms/backoffice/external/backend-api';
66
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
7-
import { UmbItemDataApiGetRequestController } from '@umbraco-cms/backoffice/entity-item';
87

98
/**
109
* A server data source for Dictionary items
@@ -15,6 +14,8 @@ export class UmbDictionaryItemServerDataSource extends UmbItemServerDataSourceBa
1514
DictionaryItemItemResponseModel,
1615
UmbDictionaryItemModel
1716
> {
17+
#itemRequestManager = new UmbManagementApiDictionaryItemDataRequestManager(this);
18+
1819
/**
1920
* Creates an instance of UmbDictionaryItemServerDataSource.
2021
* @param {UmbControllerHost} host - The controller host for this controller to be appended to
@@ -29,13 +30,7 @@ export class UmbDictionaryItemServerDataSource extends UmbItemServerDataSourceBa
2930
override async getItems(uniques: Array<string>) {
3031
if (!uniques) throw new Error('Uniques are missing');
3132

32-
const itemRequestManager = new UmbItemDataApiGetRequestController(this, {
33-
// eslint-disable-next-line local-rules/no-direct-api-import
34-
api: (args) => DictionaryService.getItemDictionary({ query: { id: args.uniques } }),
35-
uniques,
36-
});
37-
38-
const { data, error } = await itemRequestManager.request();
33+
const { data, error } = await this.#itemRequestManager.getItems(uniques);
3934

4035
return { data: this._getMappedItems(data), error };
4136
}

0 commit comments

Comments
 (0)