@@ -10,6 +10,7 @@ import { CommonMemberService, getGithubInstallationToken } from '@crowd/common_s
1010import { findMemberAffiliations } from '@crowd/data-access-layer/src/member_segment_affiliations'
1111import {
1212 MemberField ,
13+ MemberQueryCache ,
1314 addMemberRole ,
1415 fetchManyMemberOrgsWithOrgData ,
1516 fetchMemberBotSuggestionsBySegment ,
@@ -67,6 +68,17 @@ import SettingsService from './settingsService'
6768export default class MemberService extends LoggerBase {
6869 options : IServiceOptions
6970
71+ private async invalidateMemberQueryCache ( ) : Promise < void > {
72+ try {
73+ const cache = new MemberQueryCache ( this . options . redis )
74+ await cache . invalidateAll ( )
75+ this . log . debug ( 'Invalidated member query cache' )
76+ } catch ( error ) {
77+ // Don't fail the operation if cache invalidation fails
78+ this . log . warn ( 'Failed to invalidate member query cache' , { error } )
79+ }
80+ }
81+
7082 constructor ( options : IServiceOptions ) {
7183 super ( options . log )
7284 this . options = options
@@ -745,6 +757,9 @@ export default class MemberService extends LoggerBase {
745757 // trigger entity-merging-worker to move activities in the background
746758 await SequelizeRepository . commitTransaction ( tx )
747759
760+ // Invalidate member query cache after unmerge
761+ await this . invalidateMemberQueryCache ( )
762+
748763 return { member, secondaryMember }
749764 } ) ,
750765 )
@@ -1253,6 +1268,9 @@ export default class MemberService extends LoggerBase {
12531268
12541269 await SequelizeRepository . commitTransaction ( transaction )
12551270
1271+ // Invalidate member query cache after update
1272+ await this . invalidateMemberQueryCache ( )
1273+
12561274 const commonMemberService = new CommonMemberService (
12571275 optionsQx ( this . options ) ,
12581276 this . options . temporal ,
@@ -1304,6 +1322,9 @@ export default class MemberService extends LoggerBase {
13041322 )
13051323
13061324 await SequelizeRepository . commitTransaction ( transaction )
1325+
1326+ // Invalidate member query cache after bulk delete
1327+ await this . invalidateMemberQueryCache ( )
13071328 } catch ( error ) {
13081329 await SequelizeRepository . rollbackTransaction ( transaction )
13091330 throw error
0 commit comments