@@ -277,7 +277,7 @@ async function updateGroup(currentUser, groupId, data) {
277
277
278
278
// update the cache
279
279
const cache = await helper . getCacheInstance ( )
280
- cache . set ( group . id , updateGroup )
280
+ cache . set ( group . id , updatedGroup )
281
281
282
282
return updatedGroup
283
283
} catch ( error ) {
@@ -375,7 +375,7 @@ async function getGroup(currentUser, groupId, criteria) {
375
375
) } `
376
376
)
377
377
378
- if ( _ . has ( criteria , 'skipCache' ) ) {
378
+ if ( ! _ . has ( criteria , 'skipCache' ) ) {
379
379
criteria . skipCache = false
380
380
}
381
381
@@ -425,8 +425,14 @@ async function getGroup(currentUser, groupId, criteria) {
425
425
)
426
426
}
427
427
}
428
-
429
- const session = helper . createDBSession ( )
428
+
429
+ let session
430
+ const getSession = ( ) => {
431
+ if ( ! session ) {
432
+ session = helper . createDBSession ( )
433
+ }
434
+ return session
435
+ }
430
436
const cache = await helper . getCacheInstance ( )
431
437
432
438
let groupToReturn
@@ -445,21 +451,21 @@ async function getGroup(currentUser, groupId, criteria) {
445
451
const cachedGroupMembers = cache . get ( `${ groupId } -members` )
446
452
447
453
if ( ! _ . includes ( cachedGroupMembers , currentUser . userId ) ) {
448
- await helper . ensureGroupMember ( session , group . id , currentUser . userId )
454
+ await helper . ensureGroupMember ( getSession ( ) , group . id , currentUser . userId )
449
455
450
456
cachedGroupMembers . push ( currentUser . userId )
451
457
cache . set ( `${ groupId } -members` , cachedGroupMembers )
452
458
}
453
459
}
454
460
} else {
455
- groupToReturn = await helper . ensureExists ( session , 'Group' , groupId , isAdmin )
461
+ groupToReturn = await helper . ensureExists ( getSession ( ) , 'Group' , groupId , isAdmin )
456
462
cache . set ( groupId , groupToReturn )
457
463
458
464
if ( ! isAdmin ) delete groupToReturn . status
459
465
460
466
// if the group is private, the user needs to be a member of the group, or an admin
461
467
if ( groupToReturn . privateGroup && currentUser !== 'M2M' && ! helper . hasAdminRole ( currentUser ) ) {
462
- await helper . ensureGroupMember ( session , groupToReturn . id , currentUser . userId )
468
+ await helper . ensureGroupMember ( getSession ( ) , groupToReturn . id , currentUser . userId )
463
469
464
470
cache . set ( `${ groupId } -members` , [ currentUser . userId ] )
465
471
}
@@ -489,7 +495,7 @@ async function getGroup(currentUser, groupId, criteria) {
489
495
const flattenGroupIdTree = [ ]
490
496
491
497
// find child groups
492
- groupToExpand . subGroups = await helper . getChildGroups ( session , groupToExpand . id )
498
+ groupToExpand . subGroups = await helper . getChildGroups ( getSession ( ) , groupToExpand . id )
493
499
// add child groups to pending if needed
494
500
if ( ! criteria . oneLevel ) {
495
501
_ . forEach ( groupToExpand . subGroups , ( g ) => {
@@ -502,7 +508,7 @@ async function getGroup(currentUser, groupId, criteria) {
502
508
}
503
509
} else if ( criteria . includeParentGroup && ! groupToReturn . parentGroups ) {
504
510
// find parent groups
505
- groupToExpand . parentGroups = await helper . getParentGroups ( session , groupToExpand . id )
511
+ groupToExpand . parentGroups = await helper . getParentGroups ( getSession ( ) , groupToExpand . id )
506
512
// add parent groups to pending if needed
507
513
if ( ! criteria . oneLevel ) {
508
514
_ . forEach ( groupToExpand . parentGroups , ( g ) => pending . push ( g ) )
@@ -529,7 +535,9 @@ async function getGroup(currentUser, groupId, criteria) {
529
535
throw error
530
536
} finally {
531
537
logger . debug ( 'Session Close' )
532
- await session . close ( )
538
+ if ( session ) {
539
+ await session . close ( )
540
+ }
533
541
}
534
542
}
535
543
0 commit comments