I ran into some problems with some code recently that had been written for pre-ColdFusion MX 7. The code in question was designed to create a Verity collection if it didn't already exist.
In past versions of ColdFusion, if you invoked the <cfcollection action="create" /> tag on a collection that already existed, you simply use a cftry/cfcatch to skip doing an error. So, the developer before me had been writing lines of code like this:
The problem with this is that CFMX 7 no longer throws an error if the collection doesn't exist. It actually tries to re-create the Verity map. The real issue is this takes forever if you have a lot of collections on your server. In my case this was taking 20 seconds to run—which is just not acceptible.
This got me looking into other solutions. I did a search on CFLIB.org and came across a UDF called "collectionExists". This UDF used the <cfcollection action="list" /> to query a list of all Verity collections to see if a collection exists. However, I was having the same problem with this tag as I was with my cftry/cfcatch code. This action takes forever to run when you have a lot of collections on the server. This got me looking for another solution.
What I finally decided would work was to try use <cfsearch> to search over a collection to see if it exists. If the collection doesn't exist, then an error is thrown which I can capture using cftry/cfcatch. What I ended up with is a UDF that looks like this:
NOTE:2006-03-01: I revised this UDF slightly to increase speed.
I've actually posted this UDF to CFLIB, so we'll see if they update the existing function or not. In my testing this method returned ran in a few milliseconds compared to the 20 seconds it was taking before.
Comments for this entry have been disabled.