Skin Spider : Tracking Video Usage Statics And Mass Deletion

Posted November 6, 2006 at 3:28 PM by Ben Nadel

Tags: ColdFusion, Skin Spider

To learn all about Skin Spider, click here.

To view the most updated application, click here.

To view the current code base, click here.

Originally, the application was providing the user with links directly to the downloaded video files (ex. 15.mwv). This worked fine from a user's standpoint, but provided the application with no useful information. We (the application) had no sense of how often the user was viewing videos or even if a video had ever been accessed. To remedy this, I have rerouted all the video file requests through an intermediary page, view_video.cfm. This view_video.cfm file stores the video request in the database and then forwards the user onto the appropriate video file.

From the user's point of view, nothing has changed; they clicked on a link and got the video. From our standpoint, however, the world has changed. We now know all videos the user has asked for, how often a video has been viewed, which videos are viewed, which are not, and pretty much anything else that has to do with video access. While we don't really care about the user's application usage, we can now provide the user with the ability to delete videos in mass. This should give the user a very efficient and meaningful way to clean the video library.

I have updated the primary navigation in the _header_standard.cfm ColdFusion template to include a section titled "Clean Library." This section allows the user to delete multiple videos at one time based on several different types of criteria.

But, before I get into that, let me just go through a few changes. For starters, I had to add a database table to keep track of video viewing. In the Config.cfc ColdFusion component, I have added the table "video_viewing" to the XML database schema. This just stores the video ID that was requested and the date on which it was requested.

Then, I created the view_video.cfm ColdFusion template. If you take a look at that code, you will see it is quite simple. I get the requested video, add the video request to the video_viewing database table, and then perform a CFLocation to the video file. I have reworked the links on home.cfm, search.cfm, and favorites.cfm to link to this view_video.cfm tmeplate rather than directly to the video file.

So that's all I had to do to start tracking video usage. Now, we can go into the Clean Library functionality. On this page, clean_library.cfm, I have two types of delete criteria: the user can delete all videos that have been viewed less that X times or the user can delete all videos that have not been viewed in the past X weeks.

Due do the limitations of ColdFusion query of queries, I have to perform some extra queries on this page. Where I would normally do some sort of nested or sub query, I now have to perform multiple queries to get the target videos. I don't want to go into it to much here as the code is quite well commented, but basically, I have to figure out the list of video IDs that I am NOT deleting so that I can then get the videos whose IDs are NOT in the previously gotten list. Just check out clean_library.cfm and you will see what I am talking about.

What you may or may not notice is that this page pretty much duplicates the code from the delete_video.cfm template. This is really bad. This is a HUGE violation of the DRY (don't repeat yourself) principle. Now, instead of maintaining delete code in one template, we have to maintain it in two templates. This leaves us open to inconsistencies and errors. This is where we are going to start getting into Controllers, Service Layers, and Data Access Objects (DAO) ... but not yet. Basically, we are going to need a way to abstract out the code that deletes the videos in such a way that we can just invoke it rather than duplicating it in a procedural fashion.

More on this to come when we start to refactor the framework of the application.



Reader Comments

There are no comments posted for this web log entry.

Post A Comment

Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please do not post unrelated questions or large chunks of code. And, above all, please be nice to each other - we're trying to have a good conversation here.

Please review the following issues:

Author Name:


Author Email:

Author Website:

Comment:

Supported HTML tags for formatting: <strong>bold</strong>   <em>italic</em>   <code>code</code>







  • Help Wanted - Find Your Next ColdFusion Job
InVision App - Prototyping Made Beautiful With Prototyping Tools Ben Nadel's Company - Epicenter Consulting Recent Blog Comments
Feb 10, 2012 at 7:21 PM
jQuery AJAX Strips Script Tags And Inserts Them After Parent-Most Elements
Update! Instead of $(eval(options.insertAfter)).after(data['insertData']); I now use: var ajaxNode = document.createElement('span'); var parent = $(eval(options.insertAfter))[0].parentNode; ... read »
Feb 10, 2012 at 6:18 PM
jQuery AJAX Strips Script Tags And Inserts Them After Parent-Most Elements
encountered this same, what I consider, jQuery bug last week. I'm building a site in which I load some content via AJAX. This content contains Linkedin share button placeholders which Linkedin API ne ... read »
Feb 10, 2012 at 11:30 AM
Cross-Origin Resource Sharing (CORS) AJAX Requests Between jQuery And Node.js
After you understand the concepts here, this is an awesome cheatsheet for enabling CORS in just about anything http://enable-cors.org/ ... read »
JM
Feb 10, 2012 at 9:10 AM
My Safari Browser SQLite Database Hello World Example
@Amy, Here is a very good tutorial on how to use JOIN: http://www.sqltutorial.org/sqljoin-innerjoin.aspx ... read »
Feb 10, 2012 at 4:42 AM
Building A Twitter-Inspired RESTful API Architecture In ColdFusion
This is great, very useful Ben. I spotted a small typo in the api.cgm listing: <cfthrow type="Unauthroized" /> Cheers Stefan ... read »
Feb 9, 2012 at 10:35 PM
CFDirectory Filtering Uses Pipe Character For Multiple Filters (Thanks Steve Withington)
I was wondering if there would be a filter you could apply so that you got everything but what you included in the filter. As in show me all docs that are not a .pdf. ... read »
Feb 9, 2012 at 10:29 PM
Learning ColdFusion 9: Application-Specific Data Sources
@Ben, No offence, but if people were really wanting advanced features they would be using a platform like ASP.NET MVC. CFML is so structurally compromised as a tag-based scripting language that ... read »
Feb 9, 2012 at 10:03 PM
Subversion - Cleanup Failed To Process The Following Paths
@Leviaguirre, do you still have problems with this? ... read »