That is what I just spent 5 minutes writing out an email to suggest, but there is no need to send it now. I'd prefer not to set the values to null, as you may wish to write out null to the database,  but rather keep a boolean array, bitmask etc, for all the fields that is set to false when a record is initially loaded, and set to true when any change is made, or the record is new. Then the save changed method could just update those fields which have changed.
 
Updating unncessary fields does become a performance hit, and qa nightmare when you are talking about millions of records a minute in an enterprise situation.


From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Jared Rypka-Hauer
Sent: Thursday, February 09, 2006 5:00 PM
To: [email protected]
Subject: Reactor For CF Save Changed Fields (was Update Single Value)

Here's a thought...

save() persists the whole record
saveChanged() loops over an internal array, list, struct, whatever, that has the names of instance keys that have been changed since the last init/save operation...

<cffunction name="setFoo" access="public" returntype="void" output="false">
<cfargument name="foo" type="string" required="true" />
<cfset variables.instance.foo = arguments.foo>

<cfif not structKeyExists(variables.changedSinceInit,"foo")>
<cfset variables.changedSinceInit.foo = true>
</cfif>
<cfif not structKeyExists(changedSinceSave,"foo")>
<cfset variables.changedSinceSave.foo = true>
</cfif>

</cffunction>

save() does:
<cfset variables.changedSinceSaved = structNew()>

and init() does:
<cfset variables.changedSinceInit = structNew()>


SaveChanged() then uses the keynames from changedSinceSaved to write to the DB.

Save() works as per normal, saving the entire record.

Obviously, the cfif operation to check the two internal structs would be encapsulated in other functions... the above cffunction snippet is just there to give the general idea of how this might work. Also note that the changedSince structs have nothing to do with the value of the keys... they're simply there to maintain a pointer to whether or not the data has changed since the last n operation.


Any thoughts/feelings?


Laterz,

J


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

Jared C. Rypka-Hauer

Continuum Media Group LLC

http://www.web-relevant.com

Member, Team Macromedia - ColdFusion


"That which does not kill me makes me stranger." - Yonah Schmeidler


****************************************************************************

This email may contain confidential
material. If you were not an intended recipient,
Please notify the sender and delete all copies.
We may monitor email to and from our network.

 ***************************************************************************

 

Reply via email to