From ee399e6b6437cc7dbc3fbb81e59f0146f1c65fdb Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Wed, 24 Jan 2024 18:35:25 -0500 Subject: [PATCH] membershipworks: Use bulk_create for Event Work around for issues with GeneratedField. Also faster anyway. --- membershipworks/tasks/scrape.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/membershipworks/tasks/scrape.py b/membershipworks/tasks/scrape.py index 065b59f..7082644 100644 --- a/membershipworks/tasks/scrape.py +++ b/membershipworks/tasks/scrape.py @@ -115,12 +115,23 @@ def scrape_events(): category.clean_fields() category.save() - for event_data in data["evt"]: - logger.debug(event_data) - event = Event.from_api_dict(event_data) - event.clean_fields() - event.save() + events = Event.objects.bulk_create( + [Event.from_api_dict(event_data) for event_data in data["evt"]], + update_conflicts=True, + update_fields=[ + field.attname + for field in Event._meta.get_fields() + if not ( + field.auto_created + or field.many_to_many + or not field.concrete + or field.generated + or field.primary_key + ) + ], + ) + for event in events: try: event_ext = EventExt.objects.get(event_ptr=event) except EventExt.DoesNotExist: