@@ -319,28 +319,19 @@ class GroupService {
319
319
* cache. Defaults to 5 minutes.
320
320
* @return {Promise } Resolves to ID array.
321
321
*/
322
- async getGroupTreeIds ( rootGroupId , maxage = 5 * 60 * 1000 ) {
323
- const now = Date . now ( ) ;
324
- const cache = this . private . cache . groupTreeIds ;
322
+ async getGroupTreeIds ( rootGroupId ) {
323
+ const rootGroupURL = `/groups/${ rootGroupId } ` ;
324
+ const rootGroupRes = await this . private . api . get ( rootGroupURL ) ;
325
+ const rootGroupJSON = await handleApiResponse ( rootGroupRes ) ;
325
326
326
- /* Clean-up: removes stale records from the cache. */
327
- const CLEAN_UP_INTERVAL = 24 * 60 * 60 * 1000 ; // 1 day in ms.
328
- if ( now - cache . lastCleanUp > CLEAN_UP_INTERVAL ) {
329
- _ . forOwn ( cache , ( { timestamp } , key ) => {
330
- if ( now - timestamp > CLEAN_UP_INTERVAL ) delete cache [ key ] ;
331
- } ) ;
332
- cache . lastCleanUp = now ;
333
- }
327
+ const url = `/groups/${ rootGroupJSON . id } ?flattenGroupIdTree=true` ;
328
+ const response = await this . private . api . get ( url ) ;
329
+ const responseJSON = await handleApiResponse ( response ) ;
334
330
335
- /* If result is found in cache, and is fresh enough, return it. */
336
- const cached = cache [ rootGroupId ] ;
337
- if ( cached && now - cached . timestamp < maxage ) return _ . clone ( cached . data ) ;
331
+ const treeIds = responseJSON . flattenGroupIdTree ;
332
+ treeIds . unshift ( responseJSON . id ) ;
338
333
339
- /* Otherwise, fetch result from the API, write it to the cache, and
340
- * finally return that. */
341
- const res = reduceGroupIds ( await this . getGroup ( rootGroupId ) ) ;
342
- cache [ rootGroupId ] = { data : res , timestamp : now } ;
343
- return _ . clone ( res ) ;
334
+ return treeIds ;
344
335
}
345
336
346
337
/**
0 commit comments