Archive

Archive for May, 2007

Logics exam in a week :(

May 21st, 2007

I’m supposed to be able to read this to understand how the hell I’m supposed to solve a bunch of problems in a course on logics I’m reading

10 pages of this. It doesn’t even look like western letters.
I hate logics (the teachers handwriting doesn’t help) :(

buffi Uninteresting

Comments are enabled

May 14th, 2007

Ok, I’m gonna try out the spamkarma 2 plugin to see if it works nicely.
I had too much spam before to be able to keep comments enabled, but this seems really nice so let’s give it a try.

buffi Uninteresting

Optimizing you dynamic homepages. Putting the SQL at the right place

May 14th, 2007

Whenever I develop anything really, I often start out by tackling problems by doing them with a really simple approach to avoid premature optimization, since that often makes stuff messy, as well as increasing the development time. When the project finally works the way it’s supposed to you can get always get your hands dirty and optimize it then.

With the new pici in django I realized that showing pictures was sloooooow, and sought out where the problem could be. I then found out that I did a whole lot of unneeded SQL-queries in the view for showing pictures.

Each picture has a link to the next/previous picture on pici, if it’s in a gallery it has a link to the next/previous picture in that gallery and if it’s not an anonymous upload then it also has links to the next/previous picture from that user. Finally there is a link to display a random picture from pici.

My first approach was, whenever displaying a picture, get the previous and next picture in each category (that was represented for that picture) and build the links to the URL’s that way. That meant that pic http://pici.se/25 got links to http://pici.se/24 and http://pici.se/26, a random link to http://pici.se/xxxxx and also other links depending if it was in a gallery or uploaded by a user. This is obviously really stupid. Since at most one link can be clicked the SQL-queries for the other links are unneeded.

The obvious fix is first to remove all of the queries from the “show picture view”. Then change all of the links to stuff like http://pici.se/25/next , http://pici.se/25/next_in_gal and so on. When a link is clicked, the view handles the SQL needed and redirects to the new picture. This avoid unneeded queries and increased performance a whole lot. Adding a http://pici.se/random URL for the randomizer was also quite nice… since there previously wasn’t a way to get a random picture without first visiting a picture, let the view query up a random picture and then click the link. Now just visiting the URL is enough :)

There is however a downside. Without running the premature SQL, there is no way to check if a picture is the last one in a gallery and so on. One could create a hybrid solution that simply does this check beforehand, but I chose to ignore this issue since it is seldom an issue in this case, and the performance boost was a whole lot. I will go back and revisit the view code for this in a while though to check for more improvements, but right now the pictures show up really fast again, and that is the priority :)

buffi Programming & scripting, Python, Uninteresting

pici now using django

May 13th, 2007

Finally… it’s 4AM here in Sweden and I just finished the transition from php to django for pici

The major new features are

  • Nicer urls (http://pici.se/1 instead of http://pici.se/?1 , http://pici.se/p/ano41sd instead of http://pici.se/?p_ano41sd and so on…)
  • Personal galleries, both private and public
  • A nicer picture list, with options to select galleries for pictures and so on
  • The possibilty to toggle pictures from public/private
  • The ability to browse through just you own pictures using next/previous links
  • The ability to browse through galleries using next/previous links

The conversion took a bit longer then I thought. Simply rewriting and restructuring the code took a few days, which was pretty good actually, but then a lot of extra work came about in the end.
Writing the scripts for converting the old database to a new one which works fine with django, getting backwards compatible URL’s, getting picisend to work again and so on took a few days as well.

I’ve also done some other improvements “behind the scenes”. The major one is pushing out all static content through lighthttpd instead of apache, to avoid the overhead generated from apache.
I also gave postgresql a shot instead of mysql, but changed my mind so I’ll continue using mysql. Postgresql seems nice and all, but it’s better to use what you know I guess :)

Now to finish up the last bugs (some URL texts are wrong for private pictures… I think) and then go buy breakfast or something. Looks like I won’t sleep tonight :)

Also, I have ordered a nice DELL-server to use for pici, to replace the current hardware. It will be quite nice I believe (and expensive :( ).

buffi Programming & scripting, Python