Reputation: 5272
I'm trying to improve the execution time of one of my reports which uses cfcharts to print graphs. The code itself is a loop of entities and for each entity I create a chart (it's a comparison report).
By doing this inline it takes almost a minute or more to complete due to the complexity of the report so I'm trying to use cfthread for this case but I'm not sure if it's possible.
Here's the code:
<body>
<cfloop array="#uuids#" index="uuid" >
<cfthread action="run" name="t#threadCount#" output="to#threadCount#">
...
<cfchart >
...
</cfchart>
</cfthread>
...
</cfloop>
</body>
As expected cfchart will not be "printed" inside cfthread though apparently it's being executed. How can I get the output of cfthread? One possible solution would be creating an image from cfchart and just use the image to build a document at later time when all threads finished but I was wondering if there's any way of getting the cfchart output from cfthread.
Upvotes: 3
Views: 164
Reputation: 11
I was able to use cfsavecontent to save and then generate cfcharts with quotes.
Just make sure whatever queries / data variables used are saved inside the cfsavecontent block (I was having trouble with this part; scoping gets a little wonky if you aren't careful)
<body>
<cfloop array="#uuids#" index="uuid" >
<cfthread action="run" name="t#threadCount#" output="to#threadCount#">
<cfsavecontent variable="thisContent">
<cfquery name="thisQuery" datasource="dsource">
...
</cfquery>
<cfchart >
...
</cfchart>
</cfsavecontent>
</cfthread>
...
</cfloop>
<cfloop array="#uuids#" index="uuid" >
<cfthread action="join" name="t#threadCount#"/>
#thisContent#
</cfloop>
</body>
My issue that I had with this was the dynamic variable naming / calling. I'm sure that's a very easy fix, but if I called each content by the name I knew would be created, it was displayed--though this defeats the purpose of using dynamic variables. But that's another battle entirely! The answer is yes, you can use cfsavecontent with cfcharts inside a cfthread.
Upvotes: 0
Reputation: 936
I have not tested this, it's just an idea, but you could try putting cfchart inside of a cfsavecontent block.
Upvotes: 0
Reputation: 7193
Try putting a custom tag around the cfchart call and capturing generatedcontent into a variable - then access it using the threads scope. I'm not positive this will work (depending on your output format).
Upvotes: 0