Skip to content

Commit

Permalink
Back-port (clear out cached queries on reload).
Browse files Browse the repository at this point in the history
  • Loading branch information
perdjurner committed Mar 30, 2016
1 parent 3a18e96 commit 7253b96
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion wheels/CHANGELOG
Expand Up @@ -9,7 +9,7 @@ Bug Fixes
* Don't include query string when looking for image on file through imageTag() - [Per Djurner]
* Format numbers in paginationLinks() - [Per Djurner]
* Correct plugin filename case on application startup - #586 [Chris Peters]
TBD Clear out cached queries on reload - #585 [Andy Bellenie]
* Clear out cached queries on reload - #585 [Andy Bellenie]

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Expand Down
4 changes: 2 additions & 2 deletions wheels/events/onapplicationstart.cfm
Expand Up @@ -353,9 +353,9 @@
$include(template="config/#application.$wheels.environment#/settings.cfm");
// clear query (cfquery) and page (cfcache) caches
if (application.$wheels.clearQueryCacheOnReload)
if (application.$wheels.clearQueryCacheOnReload || !StructKeyExists(application.$wheels, "cachekey"))
{
$objectcache(action="clear");
application.$wheels.cachekey = Hash(CreateUUID());
}
if (application.$wheels.clearServerCacheOnReload)
{
Expand Down
13 changes: 12 additions & 1 deletion wheels/model/adapters/Base.cfc
Expand Up @@ -284,6 +284,12 @@
loc.args.psq = false;
}

// add a key as a comment for cached queries to ensure query is unique for the life of this application
if (StructKeyExists(arguments, "cachedwithin") && StructKeyExists(application.wheels, "cachekey"))
{
loc.comment = $comment("cachekey:#application.wheels.cachekey#");
}

// overloaded arguments are settings for the query
loc.orgArgs = Duplicate(arguments);
StructDelete(loc.orgArgs, "sql");
Expand All @@ -293,7 +299,7 @@
StructDelete(loc.orgArgs, "$primaryKey");
StructAppend(loc.args, loc.orgArgs);
</cfscript>
<cfquery attributeCollection="#loc.args#"><cfset loc.pos = 0><cfloop array="#arguments.sql#" index="loc.i"><cfset loc.pos = loc.pos + 1><cfif IsStruct(loc.i)><cfset loc.queryParamAttributes = $CFQueryParameters(loc.i)><cfif NOT IsBinary(loc.i.value) AND loc.i.value IS "null" AND loc.pos GT 1 AND (Right(arguments.sql[loc.pos-1], 2) IS "IS" OR Right(arguments.sql[loc.pos-1], 6) IS "IS NOT")>NULL<cfelseif StructKeyExists(loc.queryParamAttributes, "list")><cfif arguments.parameterize>(<cfqueryparam attributeCollection="#loc.queryParamAttributes#">)<cfelse>(#PreserveSingleQuotes(loc.i.value)#)</cfif><cfelse><cfif arguments.parameterize><cfqueryparam attributeCollection="#loc.queryParamAttributes#"><cfelse>#$quoteValue(str=loc.i.value, sqlType=loc.i.type)#</cfif></cfif><cfelse><cfset loc.i = Replace(PreserveSingleQuotes(loc.i), "[[comma]]", ",", "all")>#PreserveSingleQuotes(loc.i)#</cfif>#chr(13)##chr(10)#</cfloop><cfif arguments.limit>LIMIT #arguments.limit#<cfif arguments.offset>#chr(13)##chr(10)#OFFSET #arguments.offset#</cfif></cfif></cfquery>
<cfquery attributeCollection="#loc.args#"><cfset loc.pos = 0><cfloop array="#arguments.sql#" index="loc.i"><cfset loc.pos = loc.pos + 1><cfif IsStruct(loc.i)><cfset loc.queryParamAttributes = $CFQueryParameters(loc.i)><cfif NOT IsBinary(loc.i.value) AND loc.i.value IS "null" AND loc.pos GT 1 AND (Right(arguments.sql[loc.pos-1], 2) IS "IS" OR Right(arguments.sql[loc.pos-1], 6) IS "IS NOT")>NULL<cfelseif StructKeyExists(loc.queryParamAttributes, "list")><cfif arguments.parameterize>(<cfqueryparam attributeCollection="#loc.queryParamAttributes#">)<cfelse>(#PreserveSingleQuotes(loc.i.value)#)</cfif><cfelse><cfif arguments.parameterize><cfqueryparam attributeCollection="#loc.queryParamAttributes#"><cfelse>#$quoteValue(str=loc.i.value, sqlType=loc.i.type)#</cfif></cfif><cfelse><cfset loc.i = Replace(PreserveSingleQuotes(loc.i), "[[comma]]", ",", "all")>#PreserveSingleQuotes(loc.i)#</cfif>#chr(13)##chr(10)#</cfloop><cfif arguments.limit>LIMIT #arguments.limit#<cfif arguments.offset>#chr(13)##chr(10)#OFFSET #arguments.offset#</cfif></cfif><cfif StructKeyExists(loc, "comment")>#loc.comment#</cfif></cfquery>
<cfscript>
if (StructKeyExists(query, "name"))
{
Expand Down Expand Up @@ -366,5 +372,10 @@
<cfreturn loc.rv>
</cffunction>

<cffunction name="$comment" returntype="string" access="public" output="false">
<cfargument name="text" type="string" required="true">
<cfreturn "/* " & arguments.text & " */">
</cffunction>

<cfinclude template="../../plugins/injection.cfm">
</cfcomponent>

0 comments on commit 7253b96

Please sign in to comment.