@@ -222,7 +222,12 @@ def compute_hirsch_index(citation_counts):
222222
223223def get_meeting_registration_data (meeting ):
224224 """"Retrieve registration attendee data and summary statistics. Returns number
225- of Registration records created."""
225+ of Registration records created.
226+
227+ MeetingRegistration records are created in realtime as people register for a
228+ meeting. This function serves as an audit / reconciliation. Most records are
229+ expected to already exist. The function has been optimized with this in mind.
230+ """
226231 num_created = 0
227232 num_processed = 0
228233 response = requests .get (settings .STATS_REGISTRATION_ATTENDEES_JSON_URL .format (number = meeting .number ))
@@ -236,9 +241,8 @@ def get_meeting_registration_data(meeting):
236241 else :
237242 raise RuntimeError ("Could not decode response from registrations API: '%s...'" % (response .content [:64 ], ))
238243
239-
240- # for each user identified in the Registration system
241- # Create a DataTracker MeetingRegistration object
244+ records = MeetingRegistration .objects .filter (meeting_id = meeting .pk ).select_related ('person' )
245+ meeting_registrations = {r .email :r for r in records }
242246 for registration in decoded :
243247 person = None
244248 # capture the stripped registration values for later use
@@ -247,19 +251,22 @@ def get_meeting_registration_data(meeting):
247251 affiliation = registration ['Company' ].strip ()
248252 country_code = registration ['Country' ].strip ()
249253 address = registration ['Email' ].strip ()
250- matching = MeetingRegistration .objects .filter (meeting_id = meeting .pk , email = address )
251- if matching .exists ():
252- object = matching .first ()
254+ if address in meeting_registrations :
255+ object = meeting_registrations [address ]
253256 created = False
254257 else :
255258 object = MeetingRegistration .objects .create (meeting_id = meeting .pk , email = address )
256259 created = True
257- object .first_name = first_name [:200 ]
258- object .last_name = last_name [:200 ]
259- object .affiliation = affiliation
260- object .country_code = country_code
261- object .attended = True
262- object .save ()
260+
261+ if (object .first_name != first_name [:200 ] or
262+ object .last_name != last_name [:200 ] or
263+ object .affiliation != affiliation or
264+ object .country_code != country_code ):
265+ object .first_name = first_name [:200 ]
266+ object .last_name = last_name [:200 ]
267+ object .affiliation = affiliation
268+ object .country_code = country_code
269+ object .save ()
263270
264271 # Add a Person object to MeetingRegistration object
265272 # if valid email is available
0 commit comments