Skip to content

Commit 60ee96b

Browse files
committed
refactor(graph.groups): improve group type handling and cache key construction
1 parent ab1ee20 commit 60ee96b

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

packages/mgt-components/src/graph/graph.groups.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
*/
77

88
import {
9-
IGraph,
10-
prepScopes,
9+
BatchResponse,
1110
CacheItem,
1211
CacheService,
1312
CacheStore,
14-
BatchResponse,
15-
CollectionResponse
13+
CollectionResponse,
14+
IGraph,
15+
prepScopes
1616
} from '@microsoft/mgt-element';
1717
import { Group } from '@microsoft/microsoft-graph-types';
1818
import { schemas } from './cacheStores';
@@ -26,8 +26,8 @@ const groupTypeValues = ['any', 'unified', 'security', 'mailenabledsecurity', 'd
2626
* @enum {string}
2727
*/
2828
export type GroupType = (typeof groupTypeValues)[number];
29-
export const isGroupType = (value: unknown): value is GroupType =>
30-
typeof value === 'string' && groupTypeValues.includes(value as GroupType);
29+
export const isGroupType = (groupType: string): groupType is (typeof groupTypeValues)[number] =>
30+
groupTypeValues.includes(groupType as GroupType);
3131
export const groupTypeConverter = (value: string, defaultValue: GroupType = 'any'): GroupType =>
3232
isGroupType(value) ? value : defaultValue;
3333

@@ -99,8 +99,9 @@ export const findGroups = async (
9999
groupTypes: GroupType[] = ['any'],
100100
groupFilters = ''
101101
): Promise<Group[]> => {
102+
const groupTypesString = Array.isArray(groupTypes) ? groupTypes.join('+') : JSON.stringify(groupTypes);
102103
let cache: CacheStore<CacheGroupQuery>;
103-
const key = `${query ? query : '*'}*${groupTypes.join('+')}*${groupFilters}:${top}`;
104+
const key = `${query ? query : '*'}*${groupTypesString}*${groupFilters}:${top}`;
104105

105106
if (getIsGroupsCacheEnabled()) {
106107
cache = CacheService.getCache(schemas.groups, schemas.groups.stores.groupsQuery);
@@ -227,7 +228,8 @@ export const findGroupsFromGroup = async (
227228
groupTypes: GroupType[] = ['any']
228229
): Promise<Group[]> => {
229230
let cache: CacheStore<CacheGroupQuery>;
230-
const key = `${groupId}:${query || '*'}:${groupTypes.join('+')}:${transitive}`;
231+
const groupTypesString = Array.isArray(groupTypes) ? groupTypes.join('+') : JSON.stringify(groupTypes);
232+
const key = `${groupId}:${query || '*'}:${groupTypesString}:${transitive}`;
231233

232234
if (getIsGroupsCacheEnabled()) {
233235
cache = CacheService.getCache(schemas.groups, schemas.groups.stores.groupsQuery);

0 commit comments

Comments
 (0)