Rudy helped me create this query a couple of years ago to find the stats for each day of an rental ad's duration. It worked great before but now it is taking 17 seconds to process the query with over 66k records in the table.
Is the query scalable?
Is the query scalable?
Code:
<!--- retrieve stats past 40 days for an ad --->
<cffunction access="remote" name="retrieveStats40days" returntype="query">
<cfargument name="adId" type="numeric" required="true"/>
<cfargument name="adduration" type="numeric" required="true"/>
<CFQUERY name="GetStats40days" datasource="#DSN#">
SELECT thedate,
count(Stats.timeStampStats) as cnt
FROM (
select date_sub(current_date, interval i day) as thedate
from Integers t
where i <= #adduration#
) as i_40
LEFT OUTER
join Stats
on date(Stats.timeStampStats)
= i_40.thedate
and Stats.listingFk = <cfqueryparam value='#adId#' cfsqltype='cf_sql_integer'>
GROUP BY thedate
ORDER BY thedate DESC
</CFQUERY>
<cfreturn GetStats40days>
</cffunction>