@@ -6,7 +6,9 @@ import mergeWith from 'lodash.mergewith';
66import { SpamTag , User } from 'server/models' ;
77import { deleteSessionsForUser } from 'server/utils/session' ;
88import { expect } from 'utils/assert' ;
9+ import { schedulePurge } from 'utils/caching/schedulePurgeWithSentry' ;
910
11+ import { getAffiliationForUserIds } from './userDashboard' ;
1012import { getSuspectedUserSpamVerdict } from './userScore' ;
1113
1214const mergeSpamTagFields = (
@@ -58,6 +60,17 @@ const invalidateUserSessions = async (user: User) => {
5860 ) ;
5961} ;
6062
63+ const schedulePurgesForUser = async ( userId : string ) => {
64+ // should schedule purges for all communities the user has commented on, ugh
65+ const communities = await getAffiliationForUserIds ( [ userId ] ) ;
66+ const communitySubdomains = communities . get ( userId ) ?. communitySubdomains ;
67+ if ( communitySubdomains ) {
68+ for ( const communitySubdomain of communitySubdomains ) {
69+ schedulePurge ( `${ communitySubdomain } .pubpub.org` ) ;
70+ }
71+ }
72+ } ;
73+
6174export const upsertSpamTag = async ( options : UpsertSpamTagOptions ) : Promise < UpsertResult > => {
6275 const { userId, fields, status } = options ;
6376 const user = await fetchUserWithSpamTag ( userId ) ;
@@ -73,7 +86,7 @@ export const upsertSpamTag = async (options: UpsertSpamTagOptions): Promise<Upse
7386 ) ;
7487 await existingTag . update ( data as types . SpamVerdict < SpamTag > ) ;
7588 if ( status === 'confirmed-spam' && existingTag . status !== status ) {
76- await invalidateUserSessions ( user ) ;
89+ await Promise . all ( [ invalidateUserSessions ( user ) , schedulePurgesForUser ( userId ) ] ) ;
7790 }
7891 return { spamTag : existingTag , user } ;
7992 }
@@ -85,7 +98,7 @@ export const upsertSpamTag = async (options: UpsertSpamTagOptions): Promise<Upse
8598 { where : { id : userId } , limit : 1 , individualHooks : false } ,
8699 ) ;
87100 if ( status === 'confirmed-spam' ) {
88- await invalidateUserSessions ( user ) ;
101+ await Promise . all ( [ invalidateUserSessions ( user ) , schedulePurgesForUser ( userId ) ] ) ;
89102 }
90103 return { spamTag, user } ;
91104} ;
0 commit comments