prevent duplicates in mailing lists signups
@@ -953,6 +953,8 @@ async fn listen_mailchimp_webhooks(rqctx: Arc<RequestContext>, query_args: Query
// Parse the webhook as a new mailing list subscriber.
let new_subscriber = event.as_subscriber();
+ let existing = MailingListSubscriber::get_from_db(db, new_subscriber.email.to_string());
+ if existing.is_none() {
// Update the subscriber in the database.
let subscriber = new_subscriber.upsert(db).await;
@@ -962,6 +964,10 @@ async fn listen_mailchimp_webhooks(rqctx: Arc<RequestContext>, query_args: Query
event!(Level::INFO, "subscriber {} posted to Slack", subscriber.email);
event!(Level::INFO, "subscriber {} created successfully", subscriber.email);
+ } else {
+ event!(Level::INFO, "subscriber {} already exists", subscriber.email);
+ }
+
Ok(HttpResponseAccepted("ok".to_string()))
}
