@@ -198,24 +198,26 @@ def write_record(record_type, data):
198198 event_person_role = data .get ("event_person_role" )
199199 if event_id is None or person_id is None :
200200 return False
201- RrmsEventParticipation .objects .create (
201+ _event_participation , created = RrmsEventParticipation .objects .update_or_create (
202202 event_id = event_id ,
203203 person_id = person_id ,
204204 event_person_role = event_person_role ,
205- event_name = data .get ("event_name" ),
206- event_type = data .get ("event_type" ),
207- event_scale_type = data .get ("event_scale_type" ),
208- event_from = data .get ("event_from" ),
209- event_to = data .get ("event_to" ),
210- participant_start = data .get ("participant_start" ),
211- participant_end = data .get ("participant_end" ),
212- requested = data .get ("requested" ),
213- event_organization_id = data .get ("event_organization_id" ),
214- event_organization_name = data .get ("event_organization_name" ),
215- venue = data .get ("venue" ),
216- tags_json = data .get ("tags_json" ),
205+ defaults = {
206+ "event_name" : data .get ("event_name" ),
207+ "event_type" : data .get ("event_type" ),
208+ "event_scale_type" : data .get ("event_scale_type" ),
209+ "event_from" : data .get ("event_from" ),
210+ "event_to" : data .get ("event_to" ),
211+ "participant_start" : data .get ("participant_start" ),
212+ "participant_end" : data .get ("participant_end" ),
213+ "requested" : data .get ("requested" ),
214+ "event_organization_id" : data .get ("event_organization_id" ),
215+ "event_organization_name" : data .get ("event_organization_name" ),
216+ "venue" : data .get ("venue" ),
217+ "tags_json" : data .get ("tags_json" ),
218+ },
217219 )
218- return True
220+ return "created" if created else "updated"
219221 except Exception as ex :
220222 logger .error ("Failed to write %s: %s" % (record_type , str (ex )))
221223 return False
@@ -522,6 +524,8 @@ def handle(self, *args, **options):
522524 appraised_person_ids = set ()
523525 appraised_person_null_count = 0
524526 appraiser_parent_ids = set ()
527+ event_participation_created = 0
528+ event_participation_updated = 0
525529 db_write_counts = {
526530 "molnix_appraisal" : 0 ,
527531 "molnix_appraiser" : 0 ,
@@ -680,8 +684,13 @@ def handle(self, *args, **options):
680684 else :
681685 duplicate_event_keys [event_key ] = 1
682686 output_record (self .stdout , {"record_type" : "rrms_event_participation" , "data" : record })
683- if write_record ("rrms_event_participation" , record ):
687+ event_write_status = write_record ("rrms_event_participation" , record )
688+ if event_write_status :
684689 db_write_counts ["rrms_event_participation" ] += 1
690+ if event_write_status == "created" :
691+ event_participation_created += 1
692+ elif event_write_status == "updated" :
693+ event_participation_updated += 1
685694 events_stream_count += 1
686695 if record .get ("person_id" ) is not None :
687696 event_person_ids .append (record .get ("person_id" ))
@@ -728,6 +737,11 @@ def handle(self, *args, **options):
728737 db_write_counts ["rrms_person_snapshot" ],
729738 )
730739 )
740+ if event_participation_created or event_participation_updated :
741+ logger .info (
742+ "RRMS event participation upserts: created=%d updated=%d"
743+ % (event_participation_created , event_participation_updated )
744+ )
731745 if appraisal_duplicate_count :
732746 logger .warning ("Duplicate appraisal molnix_id values observed: %d" % appraisal_duplicate_count )
733747 if appraised_person_null_count :
0 commit comments