Question
starting and stopping a loop
I am importing a list of 10,000 emails into memory and then
comparing them to a database which holds over 400,000 records. It
doesnt take long for the <cfquery> to time out. I know there
must be a way to loop thru 20 or so, then stop, then loop thru the
next 20, etc. I cannot lengthen the timeout so I need to figure out
a way to process the data in chunks. Thanks.
<cfhttp method="Get"
url=" http://192.168.14.51/matt/email.CSV"
columns="Email"
name="importCSV"
delimiter="#chr(10)##chr(13)#"
textqualifier="">
<cfset counter = 0>
<cfloop index="element" list = "#CFHTTP.FileContent#" delimiters="#chr(10)##chr(13)#">
<cfset counter = counter +1>
</cfloop>
<cfset start = 1>
<cfset end = 20>
<cfset lastRow = #counter#>
<cfloop from="#start#" to="#end#" index="loop">
<cfset ThisEmail = listGetAt(cfhttp.filecontent,loop,"#chr(10)##chr(13)#")>
<CFQUERY NAME = "CheckEmail" DATASOURCE="t">
SELECT Email
FROM Subscriber_Info_New
WHERE Email = '#ThisEmail#'
</CFQUERY>
<CFIF CheckEmail.RecordCount EQ 0>
<CFQUERY NAME="Insert" datasource="t">
INSERT INTO Subscriber_Info_New
(Email)
VALUES (<cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#Trim(ThisEmail)#">)
</CFQUERY>
</CFIF>
</cfloop>
<cfhttp method="Get"
url=" http://192.168.14.51/matt/email.CSV"
columns="Email"
name="importCSV"
delimiter="#chr(10)##chr(13)#"
textqualifier="">
<cfset counter = 0>
<cfloop index="element" list = "#CFHTTP.FileContent#" delimiters="#chr(10)##chr(13)#">
<cfset counter = counter +1>
</cfloop>
<cfset start = 1>
<cfset end = 20>
<cfset lastRow = #counter#>
<cfloop from="#start#" to="#end#" index="loop">
<cfset ThisEmail = listGetAt(cfhttp.filecontent,loop,"#chr(10)##chr(13)#")>
<CFQUERY NAME = "CheckEmail" DATASOURCE="t">
SELECT Email
FROM Subscriber_Info_New
WHERE Email = '#ThisEmail#'
</CFQUERY>
<CFIF CheckEmail.RecordCount EQ 0>
<CFQUERY NAME="Insert" datasource="t">
INSERT INTO Subscriber_Info_New
(Email)
VALUES (<cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#Trim(ThisEmail)#">)
</CFQUERY>
</CFIF>
</cfloop>
