Slow API Calls when adding relationship based on database size

Hi everyone.

I am currently trying to upload 500,000 records into CRM, using a custom module with 3 relationships.

Card Transactions which then links to Card, Sale Location, Contact. These are all M:1 relationship. I have a custom API endpoint to allow us to bulk upload into Sugar (As standard API is very slow already).

The upload is extremely fast to start, but as more Card Transactions are added the slower and slower the API calls are completed.

A snippet of the code is:

$cardTran = BeanFactory::newBean('cd_CardTransactions');
$cardTran->card_no = $CARDTRANJSON['Card_Number'];
$cardTran->tran_date = isset($CARDTRANJSON['Transaction_Date']) ? date("Y-m-d", strtotime($CARDTRANJSON['Transaction_Date'])) : null;
$cardTran->sequence_no = $CARDTRANJSON['Sequence_Number'];
$cardTran->till_operator_no = $CARDTRANJSON['Till_Operator'];
$cardTran->spend_value = $CARDTRANJSON['Total_Spent_Value'];
$cardTran->points = $CARDTRANJSON['Points'];
$cardTran->till_no = $CARDTRANJSON['Till_Number'];
$cardTran->qualify_spend_value = $CARDTRANJSON['Qualifying_Retail_Value'];
$cardTran->transaction_type = $CARDTRANJSON['Transaction_Type'];				

if ($cardTran->save()) {
	if($CARDTRANJSON['Contact_ID'] != null && $CARDTRANJSON['Contact_ID'] != '')
	if($CARDTRANJSON['Card_ID'] != null && $CARDTRANJSON['Card_ID'] != '')
	if($CARDTRANJSON['Branch_ID'] != null && $CARDTRANJSON['Branch_ID'] != '')
} else {
	array_push($response['failed_lines'], $cardTran['sequence_no']);

Which essentially creates the Transaction record, then links once the save is completed. Am I missing something here? This site has 0 logic hooks or schedulers in the site, it's completely fresh.