July 2004 - Posts

ASP.Net Forums Bug in forums_MovePost sp
30 July 04 01:17 PM | alexcampbell | with no comments

I sometimes have to nurse the tech stuff on a very large online community that uses the ASP.Net Forums v1.  If I am ever condemned to an eternity of suffering, it will be spent maintaining this application.

Anyway, yesterday, I was trying to track down why the statistics (Total Threads in Forum, Total Posts in Forum) where wrong after moving posts to different forums.  After a fair bit of stumbling around through all the superfluous tiers, I found the problem in the forums_MovePost stored procedure:

  -- Update the post with a new forum id and set its approved status
  UPDATE
   Posts
  SET
   ForumID = @MoveToForumID,
   Approved = @ApproveSetting
  WHERE
   PostID = @PostID

It turns out that this only moves the parent post to the new forum, and not its replies.  How fucking stupid is that?  It was resulting in the Total Threads and Total Posts counts being wrong, but it was also wreaking havoc on the moderation - when a new reply was added to the moved post, it was going into the old forum's moderation queue. 

By adding these lines after the above, I fixed the stored procedure:

-- update all the parent post's replies so that they move into the new forum as well
  UPDATE
   Posts
  SET
   ForumID = @MoveToForumID
  WHERE
   ThreadID = @PostID

The problem then was that I was left with 25000 orphaned posts.  With a recursive update, I fixed that:

UPDATE Posts SET ForumID=(SELECT TOP 1 ForumID FROM Posts PP WHERE P.ThreadID = PP.PostID AND PP.PostLevel = 1) FROM Posts P WHERE (SELECT TOP 1 ForumID FROM Posts PP WHERE P.ThreadID = PP.PostID AND PP.PostLevel = 1) IS NOT NULL

Because of the denormalised data model in the v1 Forums, we have to re-run Statistics_ResetForumStatistics on each forum.   This is an easy TSQL way of doing this:

DECLARE @ForumID int

DECLARE ForumsCursor CURSOR FOR

SELECT ForumID FROM Forums

OPEN ForumsCursor

FETCH NEXT FROM ForumsCursor INTO @ForumID WHILE @@FETCH_STATUS = 0

BEGIN

exec Statistics_ResetForumStatistics @ForumID

FETCH NEXT FROM ForumsCursor INTO @ForumID

END

CLOSE ForumsCursor

DEALLOCATE ForumsCursor

 

Having just slammed the v1 ASP.Net Forums, I downloaded and played with the v2 Forums, and they look pretty good.

How did I break SharpReader?
30 July 04 12:55 PM | alexcampbell | 5 comment(s)

I used to use SharpReader to obsessively keep track of all the RSS feeds I enjoy reading - until two weeks ago when it just stopped loading.

When I run the .exe, the hard drive grinds for about 2 seconds and then nothing happens.

Has anyone experienced this before?


Reality TV show idea of the day:

How about we have a real reality TV show where viewers call in and evict certain shows from TV?  I would be the first to call in and try to evict Big Brother and Australian Idol, but I guess the idiot masses would overrule me.

The worst maintenance task ever (a rant)
08 July 04 12:11 AM | alexcampbell | 12 comment(s)

The below started out as a rant against the ASP.Net Forums v1, and became a kind of work-in-progress on my thoughts about the best way of developing high-quality commercial websites under budget and on time.  What follows is partly my belief, partly my devil's advocacy trying to stir up some interesting discussion on this topic.  I want to preface all this by saying that the development work I enjoy the most is object-oriented, and I think OO architecture has a place in nearly everything we do.

Possibly the most painful thing I contemplate in my working life is maintaining an old client web site that uses the ASP.Net Forums v1 to run an online community with thousands of active users and tens of thousands of posts.  Usually, this would be a pointless blog topic, but right now I think it illustrates a lot of what I have been saying about ASP.Net architecture.

My starting position is thus:  the majority of what we do as web application developers is create an interface between a web browser and the persistance medium (usually SQL Server database tables for me).  The decisions that we make about what is in between these two end-points really should have no effect on the end users, all they see is formatted HTML.

The ASP.Net Forums have 5 tiers in between these two end-points.

  • ASPX pages
  • ----------------------------------------------------------------------------
  • Custom server controls
  • Business logic layer (ie Threads class containing static methods)
  • Custom objects (ie Thread and ThreadCollection classes containing the OO data representations of what is in the database)
  • Data Access Layer
  • Stored Procedures in SQL Server
  • ----------------------------------------------------------------------------
  • Database tables in SQL Server

An alternative architecture:

  • ASPX pages
  • ----------------------------------------------------------------------------
  • Codebehind containing SQL queries / statements
  • ----------------------------------------------------------------------------
  • Database tables in SQL Server

Try this test: pick an average person on the street.  Choose someone who is accompanied by an attractive member of the opposite sex so you can be sure they're not a professional software engineer.  Get this layperson to tell you about their favorite websites, and you will find that they have no idea how many tiers there are in between them and the data they see.  You will almost certainly find that the most interesting sites to the user are the ones that have been able to adapt to users needs more quickly - the ones that have the least tiers.  Users don't care what's happening behind the scenes - they're looking for information.

Let's say I wanted to add voting functionality so that users could rate each post (ie like Slashdot).  To do this on the 7 tier architecture, I could spend two weeks working up and down each of the tiers.  Extra tiers make maintaining/enhancing a site far more difficult.

It's also worth mentioning that the most useful sites to end users are sites whose construction didn't bankrupt their owners during the construction phase.  I'm convinced that the 7 tier site above costs two or three times as much to develop as the 3 tier alternative.  A clever company that is starting an online community would want the 3 tier site and use the money they save on site enhancements after 6 months of watching their users.  Successful web applications are able to change rapidly based on user feedback.

The craziest part of all this is that you can't ever return anything other than a string or a binary file to a web browser.  You can't ever pass a ForumPost object to a web browser and let it figure out how to display it.  All you can do is either Response.Write() strings or use ASP.Net's more refined methods for formatting strings before sending them to browsers (ie DataGrids, Repeaters, Labels).  The database might be a bit more clever - SQL Server provides a whole stack of datatypes for you - but all that is doing is ensuring that your datatype and data relationship requirements are being enforced at the persistance medium.  But at the end of the day, you are going to convert these into strings before you send them to Joe Blog's Internet Explorer.  What do you gain from replicating the database structure in your middle tier?


Ok, so the ASP.Net Forums v1 are an extreme example.  But now I go to try to figure out why the Thread sorting mechanism isn't working.  Once I dig through the tiers to figure out which stored procedure is being called, I end up in a file called SqlDataProvider.cs.  It is 4396 lines long.  What a fucking mess.  Why would you put every single data access call for the entire application in ONE file?  I gather that this is considered a best-practise in case you ever want to change database servers (remember when Microsoft went broke and left all its SQL Server customers out to dry... no?).  How many people are using Oracle or mySql to power the ASP.Net forums?  Even if I was forced to rewrite this application tomorrow for Oracle, I don't think this architecture would make it substantially easier.

Fuck, the stored procedure is 200 lines long.  It contains more logic, mostly in the form of if/else if/else statements, none of which are commented or indented.


I'll leave it at that for tonight.  I want to repeat my initial statement: the preceeding is more an attempt at provoking discussion than my own personal views.  :-)

OT: Regime Change (also known as 'Nation Building')
04 July 04 04:49 PM | alexcampbell | 5 comment(s)

When we hear the words 'regime change' or 'nation building', we usually think of them as things that the USA does to Iraq, Iran, Afghanistan, Yugoslavia, El Salvador, Nicaragua, Panama, Chile, Haiti, Guatemala, Cuba, South Vietnam,  etc.  As an aside, it's worth noting that these doctrines have made all of these places highly rated tourist destinations for Western tourists.  I've spent this weekend reading Noam Chomsky's Hegemony or Survival, and it has induced some urgency into my view that 'regime change' is something that the people of the USA need to do to the USA.

I imagine that many Americans are going to see Fahrenheit 9/11 this weekend.  As I live in Australia, I probably won't see it until 26 July so I'm sitting on the couch at home watching Bowling for Columbine this afternoon.  I've seen it several times, but it is still the only movie I've ever seen that makes me feel the need to cry.  It makes me think: there can be no doubt that Noam Chomsky is a brilliant thinker with cutting insight into the state of international relations, but he is inaccessible to a wide audience.  This is where Michael Moore comes in - he presents many of Chomsky's issues and viewpoints in such an emotional and accessible way that any moderately educated person in the Western World can understand them.

Reading about the wide-spread reactions to Fahrenheit 9/11 gives me hope that regime change is on the way for the USA.

Whidbey Beta 1 Release coincides with Mono release...
01 July 04 10:36 AM | alexcampbell | 6 comment(s)

I'm not a cynical person.

A cynical person would put some facts together and form them into an idea.  Consider that Microsoft released a bunch of .Net 2.0 beta products only one day before the well published release date of Mono, the open source cross platform framework that works kind of like .Net v1.

So much hype surrounded the .Net 2.0 beta releases that the Mono release nearly went unnoticed around here.  Of course, much of that hype was simply people around http://weblogs.asp.net saying, “I downloaded Whidbey express betas, they're great and so am I”.  With all the new features in Whidbey, none of these people are going to get excited about the features in Mono that we had on .Net 1.0 three years ago.

Anyway, this really just proves my long held view that Mono is always going to be a couple of years behind the Microsoft .Net development cycle and will therefore be pretty useless commercially.  With this release timing coincidence, Microsoft is just pushing Mono further into the darkness.

More Posts