Rename roleTargets -> roleTarget (#16247)
This commit is contained in:
+13
@@ -0,0 +1,13 @@
|
||||
import {
|
||||
appendCommonExceptionCode,
|
||||
CustomException,
|
||||
} from 'src/utils/custom-exception';
|
||||
|
||||
export class WorkspaceCacheException extends CustomException<
|
||||
keyof typeof WorkspaceCacheExceptionCode
|
||||
> {}
|
||||
|
||||
export const WorkspaceCacheExceptionCode = appendCommonExceptionCode({
|
||||
MISSING_DECORATOR: 'MISSING_DECORATOR',
|
||||
INVALID_PARAMETERS: 'INVALID_PARAMETERS',
|
||||
} as const);
|
||||
+9
-9
@@ -8,7 +8,7 @@ import { CacheStorageNamespace } from 'src/engine/core-modules/cache-storage/typ
|
||||
import { WORKSPACE_CACHE_KEY } from 'src/engine/workspace-cache/decorators/workspace-cache.decorator';
|
||||
import { WorkspaceCacheService } from 'src/engine/workspace-cache/services/workspace-cache.service';
|
||||
|
||||
const WORKSPACE_ID = 'test-workspace-id';
|
||||
const WORKSPACE_ID = '20202020-0000-4000-8000-000000000000';
|
||||
|
||||
class MockFeatureFlagsCacheProvider extends WorkspaceCacheProvider<{
|
||||
testData: string;
|
||||
@@ -259,8 +259,8 @@ describe('WorkspaceCacheService', () => {
|
||||
await service.invalidateAndRecompute(WORKSPACE_ID, ['featureFlagsMap']);
|
||||
|
||||
expect(cacheStorageService.mdel).toHaveBeenCalledWith([
|
||||
'feature-flag:feature-flags-map:test-workspace-id:data',
|
||||
'feature-flag:feature-flags-map:test-workspace-id:hash',
|
||||
'feature-flag:feature-flags-map:20202020-0000-4000-8000-000000000000:data',
|
||||
'feature-flag:feature-flags-map:20202020-0000-4000-8000-000000000000:hash',
|
||||
]);
|
||||
expect(mockProvider.computeForCache).toHaveBeenCalledWith(WORKSPACE_ID);
|
||||
expect(cacheStorageService.mset).toHaveBeenCalled();
|
||||
@@ -306,10 +306,10 @@ describe('WorkspaceCacheService', () => {
|
||||
|
||||
expect(cacheStorageService.mdel).toHaveBeenCalledWith(
|
||||
expect.arrayContaining([
|
||||
'feature-flag:feature-flags-map:test-workspace-id:data',
|
||||
'feature-flag:feature-flags-map:test-workspace-id:hash',
|
||||
'metadata:permissions:roles-permissions:test-workspace-id:data',
|
||||
'metadata:permissions:roles-permissions:test-workspace-id:hash',
|
||||
'feature-flag:feature-flags-map:20202020-0000-4000-8000-000000000000:data',
|
||||
'feature-flag:feature-flags-map:20202020-0000-4000-8000-000000000000:hash',
|
||||
'metadata:permissions:roles-permissions:20202020-0000-4000-8000-000000000000:data',
|
||||
'metadata:permissions:roles-permissions:20202020-0000-4000-8000-000000000000:hash',
|
||||
]),
|
||||
);
|
||||
});
|
||||
@@ -322,8 +322,8 @@ describe('WorkspaceCacheService', () => {
|
||||
await service.flush(WORKSPACE_ID, ['featureFlagsMap']);
|
||||
|
||||
expect(cacheStorageService.mdel).toHaveBeenCalledWith([
|
||||
'feature-flag:feature-flags-map:test-workspace-id:data',
|
||||
'feature-flag:feature-flags-map:test-workspace-id:hash',
|
||||
'feature-flag:feature-flags-map:20202020-0000-4000-8000-000000000000:data',
|
||||
'feature-flag:feature-flags-map:20202020-0000-4000-8000-000000000000:hash',
|
||||
]);
|
||||
});
|
||||
|
||||
|
||||
+20
-5
@@ -3,7 +3,7 @@ import { DiscoveryService, Reflector } from '@nestjs/core';
|
||||
|
||||
import crypto from 'crypto';
|
||||
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
import { isDefined, isValidUuid } from 'twenty-shared/utils';
|
||||
|
||||
import { WorkspaceCacheProvider } from 'src/engine/workspace-cache/interfaces/workspace-cache-provider.service';
|
||||
|
||||
@@ -12,10 +12,14 @@ import { CacheStorageService } from 'src/engine/core-modules/cache-storage/servi
|
||||
import { CacheStorageNamespace } from 'src/engine/core-modules/cache-storage/types/cache-storage-namespace.enum';
|
||||
import { PromiseMemoizer } from 'src/engine/twenty-orm/storage/promise-memoizer.storage';
|
||||
import { WORKSPACE_CACHE_KEY } from 'src/engine/workspace-cache/decorators/workspace-cache.decorator';
|
||||
import {
|
||||
WorkspaceCacheException,
|
||||
WorkspaceCacheExceptionCode,
|
||||
} from 'src/engine/workspace-cache/exceptions/workspace-cache.exception';
|
||||
import {
|
||||
WORKSPACE_CACHE_KEYS_V2,
|
||||
WorkspaceCacheKeyName,
|
||||
type WorkspaceCacheDataMap,
|
||||
type WorkspaceCacheKeyName,
|
||||
type WorkspaceCacheResult,
|
||||
} from 'src/engine/workspace-cache/types/workspace-cache-key.type';
|
||||
import { type WorkspaceLocalCacheEntry } from 'src/engine/workspace-cache/types/workspace-local-cache-entry.type';
|
||||
@@ -70,10 +74,21 @@ export class WorkspaceCacheService implements OnModuleInit {
|
||||
}
|
||||
}
|
||||
|
||||
async getOrRecompute<const K extends WorkspaceCacheKeyName[]>(
|
||||
public async getOrRecompute<const K extends WorkspaceCacheKeyName[]>(
|
||||
workspaceId: string,
|
||||
workspaceCacheKeyNames: K,
|
||||
): Promise<WorkspaceCacheResult<K>> {
|
||||
if (
|
||||
!isDefined(workspaceId) ||
|
||||
workspaceCacheKeyNames.length === 0 ||
|
||||
!isValidUuid(workspaceId)
|
||||
) {
|
||||
throw new WorkspaceCacheException(
|
||||
'Invalid parameters: workspace ID and cache key names are required',
|
||||
WorkspaceCacheExceptionCode.INVALID_PARAMETERS,
|
||||
);
|
||||
}
|
||||
|
||||
const memoKey =
|
||||
`${workspaceId}-${[...workspaceCacheKeyNames].sort().join(',')}` as const;
|
||||
|
||||
@@ -117,7 +132,7 @@ export class WorkspaceCacheService implements OnModuleInit {
|
||||
return result as WorkspaceCacheResult<K>;
|
||||
}
|
||||
|
||||
async invalidateAndRecompute(
|
||||
public async invalidateAndRecompute(
|
||||
workspaceId: string,
|
||||
workspaceCacheKeys: WorkspaceCacheKeyName[],
|
||||
): Promise<void> {
|
||||
@@ -127,7 +142,7 @@ export class WorkspaceCacheService implements OnModuleInit {
|
||||
await this.recomputeCache(workspaceId, workspaceCacheKeys);
|
||||
}
|
||||
|
||||
async flush(
|
||||
public async flush(
|
||||
workspaceId: string,
|
||||
workspaceCacheKeys: WorkspaceCacheKeyName[],
|
||||
): Promise<void> {
|
||||
|
||||
@@ -3,7 +3,7 @@ import { type ObjectsPermissionsByRoleId } from 'twenty-shared/types';
|
||||
import { type FlatApplicationCacheMaps } from 'src/engine/core-modules/application/types/flat-application-cache-maps.type';
|
||||
import { type FeatureFlagKey } from 'src/engine/core-modules/feature-flag/enums/feature-flag-key.enum';
|
||||
import { type AllFlatEntityMaps } from 'src/engine/metadata-modules/flat-entity/types/all-flat-entity-maps.type';
|
||||
import { type UserWorkspaceRoleMap } from 'src/engine/metadata-modules/workspace-permissions-cache/types/user-workspace-role-map.type';
|
||||
import { type UserWorkspaceRoleMap } from 'src/engine/metadata-modules/role-target/services/workspace-user-workspace-role-map-cache.service';
|
||||
|
||||
export const WORKSPACE_CACHE_KEYS_V2 = {
|
||||
flatObjectMetadataMaps: 'flat-maps:object-metadata',
|
||||
|
||||
Reference in New Issue
Block a user