CSV INSERT TAKES OVER 24 HOURS
Hi
I have a simple CSV with 5 columns. Name, Email, Custom1, Custom2, Custom3, Custom4
The CSV has 120 000 rows.
When I insert the CSV into a MySql DB, it starts off perfectly. About 2000 is 3 minutes.
Thereafter it slows down alarmingly to about 1 record every second or 2.
I really need to speed this process up.
My code is fairly simple... See below:
Please can someone assist me with this as it is causing me endless headaches!
Best regards
Delon
<cffile action="upload" filefield="CSVFILE" destination="C:\inetpub\vhosts\abc.com\httpdocs\login\csvfiles\">
<cffile action="READ" file="#CSVFILE#" variable="thefile">
<cfset processed=0>
<cfloop list="#thefile#" delimiters="#chr(10)#" index="el">
<!--- check that that there is no comma in name --->
<cfif listlen(el) GTE "2" AND findnocase('@',listgetat(el,'2')) NEQ 0>
<!--- check that we dont have this email already --->
<cfquery name="CheckDup" datasource="#application.db#">
SELECT name
FROM tblrecipients
WHERE <!--- name = '#trim(listgetat(el,'1'))#'
AND --->
email = '#trim(listgetat(el,'2'))#'
AND ListID = #ListID#
AND userid = #Session.userid#
</cfquery>
<cfif CheckDup.RecordCount eq 0>
<cfquery datasource="#application.db#" timeout="9999999">
INSERT INTO tblrecipients(name,email,listid,userid,COLUMNA,COLUMNB,COLUMNC,COLUMND)
VALUES('#trim(listgetat(el,'1'))#','#trim(listgetat(el,'2'))#',#ListID#,#Session.userid#,
<cftry>'#trim(listgetat(el,'3'))#'<cfcatch type="any"> '</cfcatch></cftry>,
<cftry>'#trim(listgetat(el,'4'))#'<cfcatch type="any"> '</cfcatch></cftry>,
<cftry>'#trim(listgetat(el,'5'))#'<cfcatch type="any"> '</cfcatch></cftry>,
<cftry>'#trim(listgetat(el,'6'))#'<cfcatch type="any"> '</cfcatch></cftry>
)
</cfquery>
<cfset processed=processed+1>
</cfif>
</cfif>
</cfloop>
