@@ -662,7 +662,6 @@ export default class ActivityService extends LoggerBase {
662662 )
663663
664664 // map existing activities to payloads for further processing
665- const memberIdsToLoad = new Set < string > ( )
666665 const payloadsNotInDb : IActivityProcessData [ ] = [ ]
667666 for ( const payload of relevantPayloads ) {
668667 const existingRelation = singleOrDefault ( existingActivityRelations . rows , ( a ) => {
@@ -693,73 +692,16 @@ export default class ActivityService extends LoggerBase {
693692 return aTimestamp === pTimestamp
694693 } )
695694
696- // if we have member ids we can use them to load members from db
697695 if ( existingRelation ) {
698696 payload . activityId = existingRelation . activityId
699697 payload . dbActivityRelation = existingRelation
700-
701- memberIdsToLoad . add ( existingRelation . memberId )
702-
703- if ( existingRelation . objectMemberId ) {
704- memberIdsToLoad . add ( existingRelation . objectMemberId )
705- }
706- } else {
707- payloadsNotInDb . push ( payload )
708698 }
709- }
710-
711- if ( memberIdsToLoad . size > 0 ) {
712- // load members by member ids
713- const dbMembers = await logExecutionTimeV2 (
714- async ( ) => this . memberRepo . findByIds ( Array . from ( memberIdsToLoad ) ) ,
715- this . log ,
716- 'processActivities -> memberRepo.findByIds' ,
717- )
718-
719- // and map them to payloads
720- for ( const payload of relevantPayloads . filter ( ( p ) => p . dbActivityRelation ) ) {
721- let addToPayloadsNotInDb = false
722- payload . dbMember = singleOrDefault (
723- dbMembers ,
724- ( m ) => m . id === payload . dbActivityRelation . memberId ,
725- )
726- if ( ! payload . dbMember ) {
727- this . log . warn (
728- {
729- memberId : payload . dbActivityRelation . memberId ,
730- } ,
731- 'Member not found! We will try to find an existing one or create a new one!' ,
732- )
733699
734- addToPayloadsNotInDb = true
735- } else {
736- payload . dbMemberSource = 'activity'
737- }
738-
739- if ( payload . dbActivityRelation . objectMemberId ) {
740- payload . dbObjectMember = singleOrDefault (
741- dbMembers ,
742- ( m ) => m . id === payload . dbActivityRelation . objectMemberId ,
743- )
744-
745- if ( ! payload . dbObjectMember ) {
746- this . log . warn (
747- {
748- objectMemberId : payload . dbActivityRelation . objectMemberId ,
749- } ,
750- 'Object member not found! We will try to find an existing one or create a new one!' ,
751- )
752-
753- addToPayloadsNotInDb = true
754- } else {
755- payload . dbObjectMemberSource = 'activity'
756- }
757- }
758-
759- if ( addToPayloadsNotInDb ) {
760- payloadsNotInDb . push ( payload )
761- }
762- }
700+ // Regardless of whether the activity already exists, we always resolve the
701+ // owning member from identities (username/email/etc.) instead of trusting
702+ // the existing relation.memberId. This ensures activities always follow
703+ // the current owner of the identity.
704+ payloadsNotInDb . push ( payload )
763705 }
764706
765707 if ( payloadsNotInDb . length > 0 ) {
0 commit comments