Skip to main content
Participating Frequently
September 21, 2009
Question

question about cfc perfomance

  • September 21, 2009
  • 3 replies
  • 979 views

Hi to ALL!!!

I have some pages with <form> tag and I have SEVERAL  <input> tags, wich may repeate (present) in all  of this <forms>. I'm trying to do efficient validation (in my case, EFFICIENT means - optimize in memory and cpu usage)

So thirst , I've made validation.cfc, wich  inclueds ALL validation rules (about 30 rules) for ALL inputs, and it looks like

METHOD #1

<cfscript>

function Valid() {

     var arErrorlist=arraynew(1);

     if (structkeyexists(form,"input1")){

     some code - if it's true,then - arrayappend(arErrorlist,"error mesage 1")  

     }

if (structkeyexists(form,"input2")){

     some code - if it's true,then - arrayappend(arErrorlist,"error mesage 2")  

     }

....................

if (structkeyexists(form,"input30")){

     some code - if it's true,then - arrayappend(arErrorlist,"error mesage 30")  

     }

return arErrorlist;

}

</cfscript>

So, on action page I have:

<cfscript>

request.one=createobject("component",validation);

request.two=request.one.validation();

</cfscript>

If something wrong - I have request.two with arErrorlist

But I think, this method is BAD, because if I check a form with only 3 inputs, server have to parsing ALL 30 "if (structkeyexists(form,"input N "))"

In other hand I can use  validation.cfc , wich can look like

METHOD #2

<cfscript>

     this.arErrorlist=arraynew(1);

     function check_input1 () {

     some code - if it's true,then - arrayappend(this.arErrorlist,"error mesage 1")  

     }

function check_input2 () {

     some code - if it's true,then - arrayappend(this.arErrorlist,"error mesage 2")  

     }

....................

function check_input30 () {

     some code - if it's true,then - arrayappend(this.arErrorlist,"error mesage 30")  

     }

</cfscript>

And action page can be:

<cfscript>

request.one=createobject("component",validation);

request.one.check_input N  //what actualy need on current form

.........

request.one.check_input N  //what actualy need on current form

</cfscript>

If something wrong - I have request.one.arErrorlist

And finaly (METHOD #3) I can use on  action page cfc with "extend" to validation.cfc from method #2

So, what do you think - wich method - #1, #2 or #3 will be more efficient?

Thanks for your answers!!!

    This topic has been closed for replies.

    3 replies

    October 1, 2009

    Try to run

    <cfloop item="ff" collection="#form#">
        <cfoutput>#ff# = #form[ff]#</cfoutput>
    </cfloop>

    in your validation/processing page.

    It may give you some ideas...

    vovasvvAuthor
    Participating Frequently
    October 18, 2009

    Thanks for your answers, you've given to me some idea, but I don't now how to do it:

    switch(arguments.rule)
    {
         case "input1": ... your code here ... ;
         case "input2": ... your code here ... ;
         ...
    }

    Good idea, but what about

    arguments.rule ?????

    On one hand, as I now:  <cfswitch...> is not a loop, it does not check multiple values.  It checks a single value agains multple choices.

    But on other hand, I can convert list of form's names to query (for exmp -  qMyquery) with 1 column, for examp. - form_names. After that, I'll be able to do cfswich expression like #qMyquery.form_names# - is it a right way?

    If not, I don't understand how to apply your recomendation. Can somebody give me some examples?

    vovasvvAuthor
    Participating Frequently
    September 22, 2009

    TO

    Alexei Yakovenko

    Thanks for your advise, but I can't apply it.

    For instance, I have a form with 3 inputs and each of them has  personel  condition:

    thirst - I check for RegExp

    second - must be from 3 to 10 simbols

    third - muct be Numeric only, there for I have a deferent argument for each input, so I can't use cfswitch.

    Aditionaly, I don't now ( and it's my point for uderstandig) some "resourse-expensive" features of CF parsing (I suppose specially in JVM ) :

    What is more resourse-intensive -

    to process 1 cfc with 30 if() and 2 request "object" variables  or to process 1 cfc with less then 30 functions and 1  request "object" variable with instance data?