depends on what these methods do, whether they are...
# cfml-general
w
depends on what these methods do, whether they are truly for each request or whether they can survive as singletons in the application scope
g
can you explain this line a bit whether they can survive as singletons in the application scope
w
first, is it just a bunch of functions or are they functions in a cfc ?
g
they are functions inside a cfc
w
what do they do
what is their purpose
g
just performing normal operations, mostly 90% of them returning queries data
w
the same data for every request, like a list of u.s. states, or do they have arguments that cause them to return different data each time they're called?
g
they do have arguments
w
do they set properties / variables in the cfc itself?
g
properties like cfproperty, i think no
variables scopes things - yes
like variables.dsn
w
well, if they mutate the cfc in any way, like setting cfproperties or setting variables in the variables scope that other functions in the cfc reference, it may not be safe to be used as a singleton, where you instantiate the cfc once into the application scope and all calls to it use the same single instance of that object
when i say the variables scope, i do NOT mean local variables in each function
if you want to paste the cfc code, will be easier to answer whether it can/should go in the application scope
g
sure
let me create a gist for it
w
also, do you know if the original author put them in the request scope for a specific reason?
g
no
and also not all cfc's have init method, some cfc has direct call to the datasource
w
so this cfc would be safe to create once in the application scope and call it from there. know that saying that is a massive over-simplification of what SHOULD be done with it, but if you create for example :
Copy code
application.myCFC = new path.to.myCFC( datasource="TheDSN" );
in the onApplicationStart() method in application.cfc, then you can call methods in it as
application.myCFC.DeletecSubmission( ... )
directly instantiating components in the application is an old pattern. valid, but there are better ways to do it (such as using a Dependency Injection framework like DI/1 or Wirebox
is this component you pasted created in each request?
g
Yes
That is what is bothering me
w
ok, so moving the instantiation to application scope would be an improvement over what you have now in my opinion
g
I wonder if there is something which I could use it as a mixin
Approach
w
how do you mean
if this is really old code it my stem from the days when 'move it to the request scope for thread safety' was used as the rationale a lot, even when it didn't apply
g
But we'll yeah that might not work because I have to manually do changes
But cf has improved a lot so I think it should be thread safe
w
if you cast it into the application scope, you'll save the 'cost' of creating the object on each request, which is minimal
it's only thread safe if the code is written to be
and what i see in your paste, it should be fine, unless you're switching datasources each time
g
Nah no data sources switch
It's just one
w
then it should be fine
g
Awesome cool
w
fwiw, the delete query on line 38 doesn't need a name attribute
if it doesn't return anything then leave name off, or add the result attribute, which will give you info about how many rows may have been deleted
@gsr very important: you need to local scope all the variables inside the functions, including query names, if you move this to application scope
g
Yes thanks for this information
This is really old code so there are lots of unneeded and mistaken things
cleaned up a bit. note that the two cfinvoke calls specify returnvariable, but you never actually use them, so you could omit those attributes. i added the local var scope for them anyway
g
Ok
@websolete ++
w
again, what you're planning on doing, move to application scope, is an improvement, but there's a lot more that can be done. but it requires a bit more advanced code and leveraging a DI framework. if you're not comfortable with that, just stick with small improvements like this
g
Sure adding a di framework will be extra work if I had plans to do more on this I would consider coldbox
I tried ++ to give karma thingy but that does not seems be working. 😎
w
i don't think the bot has been alive for a long time
g
Yeah but thanks for the guidance Much appreciated
w
i think brad wood broke it. he was scamming the bot to make it seem like he was helping people
😂 2