Skip to content

Commit 5e1e4fc

Browse files
authored
fix: change group type handling and cache key construction (#3359)
* refactor(graph.groups): improve group type handling and cache key construction * chore(schemas): increment version numbers for cache schemas
1 parent ab1ee20 commit 5e1e4fc

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const schemas = {
2424
userFilters: 'userFilters',
2525
cardState: 'cardState'
2626
},
27-
version: 4
27+
version: 5
2828
},
2929
photos: {
3030
name: 'photos',
@@ -43,15 +43,15 @@ export const schemas = {
4343
groupPeople: 'groupPeople',
4444
peopleQuery: 'peopleQuery'
4545
},
46-
version: 3
46+
version: 4
4747
},
4848
groups: {
4949
name: 'groups',
5050
stores: {
5151
groups: 'groups',
5252
groupsQuery: 'groupsQuery'
5353
},
54-
version: 5
54+
version: 6
5555
},
5656
get: {
5757
name: 'responses',
@@ -65,7 +65,7 @@ export const schemas = {
6565
stores: {
6666
responses: 'responses'
6767
},
68-
version: 2
68+
version: 3
6969
},
7070
files: {
7171
name: 'files',

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)