I created a discussion board. Each entry displays the
preferences of the user who posted the entry, such as 'Allow
Private Messages', 'Allow Emails' etc. When looping through the
entries, I have to query the database to get the preferences for
each individual 'poster'. Because I thought it would increase
performance, I created a CFC method and call the Object into the
session scope. Then I initiate the method when looping through the
results and setting a variable in the THIS scope in the instance to
the query result value.
When comparing the two ways of doing it, there's a four-fold
increase in load time using the CFC, this doesn't seem right and I
suspect I am doing something wrong.
Below are the two different approaches, maybe someone can
help me:
Without CFC:
<cfoutput query="results">
<cfquery name=getPoster datasource="xxx">
select first_name
from users
where user_id = #results.user_id#
</cfquery>
</cfoutput>
With a CFC:
CFC Code:
<cfcomponent>
<cfset THIS.user_data_id = 0>
<cffunction name="getPosterPrefs" access="public"
returntype="query">
<cfargument name="user_data_id" required="yes"
type="numeric">
<cfquery name="getposter" datasource="xxx">
SELECT allow_pm, pm_ignore_list, show_email
FROM forum_user_data
WHERE user_data_id = #THIS.user_data_id#
</cfquery>
<cfreturn getPMprefs1>
</cffunction>
</cfcomponent>
In the page:
<cfif (not structKeyExists(session, "replyPrefs"))>
<cflock name="lock_replyPrefs" timeout="5"
type="exclusive">
<cfobject component="/tvocomponents.forums"
name="session.replyPrefs">
</cflock>
</cfif>
<cfoutput query="results">
<cfset session.replyPrefs.user_data_id =
#getReplyPoster.user_data_id#>
#message#
<cfif
#session.replyPrefs.getPosterPrefs(getReplies.thread_reply_user_id).allow_pm#
eq 1>Allow Private Messages</cfif>
</cfoutput>
Thanks for any help.