Another round of development on Hyperactive is nearly complete. In this round of features, we’ve concentrated on getting the code ready for production use. This has consisted mostly of the following tasks:
- caching
- localization
- the ability to leave comments
Caching
Since Ruby is a slow language (it takes a long time to do stuff compared to most other languages) and Rails isn’t a particularly speedy framework, we don’t want to be pulling all the information to construct a page out of the database and building the page every time somebody requests it. The site needs to be fast enough to not fold up under heavy load.
So, the code has been set up to use the fastest possible solution to this set of problems – the full-page caching mechanism in Rails. For any content show page (i.e. show an article, show an event, or show a video), and for the front page of the site, the page is assembled from the database and rendered as HTML the first time it’s requested. This rendered page gets cached on disk. The next time somebody requests the same page, instead of firing up Rails and hitting the database and doing all the calculations necessary to show the page, the Apache server looks in its cache and says “oh, yeah, I’ve got this one, here you go” – which is maybe 100 times faster than assembling the page dynamically. This means that more people can be looking at the site at any given time without the server flipping out.
As with anything, there are a few trade-offs involved. For one thing, the fact that we’re caching the full page rather than just parts of it means that the page needs to be the same for everybody. This might not seem like a big deal at first, but it means we can’t (easily) have stuff like “Now logged in as Noam”, or show different controls on the page based on whether a user is an admin or not. If we did, the user “Marcos” might log into the site, take a look at a page which Noam had previously viewed, see the message “Now logged in as Noam”, and suffer a major identity crisis (“Why am I up here in the mountains? MIT seems so much more comfortable at this time of year.”). The repercussions could be too much to bear, especially if the situation was reversed and Chomsky tried to pick up an AK-47 and head for the mountains. None of us wants to be responsible for this.
The way we’ve solved the problem is to put things like administrative controls into the page as AJAX calls. When viewing an article, if you click on the “inappropriate article?” link, the page asks the server to grab the proper controls for your user role – if you have the ability to hide content, you see the “hide content” controls, if you don’t have the ability to hide content, you see the “report this content” controls. Since this part of the page comes back as the result of a fresh request to the server, we can check the user’s role when the request takes place, which gets around the problem of the cached page.
We still need to do caching for the list pages, and a few other pages, but the front page and the content pages seemed like the best place to start.
Localization
The site can now be fully localized into any UTF-8 language. We’ve used the click-to-globalize plugin together with the globalize plugin to provide translation services. Basically, in order to translate the site’s user interface into your language, all you need to do is log in as a translator, and click directly on the piece of text you want to translate. When you do this, an in-place editor appears on the page, you type in the translated text, and hit a “save” button. This saves the translated text in the database. You can see this in action in the “text area transformation” screencast video on the bottom of the click-to-globalize page.
Currently, any site should only be in one language, but this should make it really easy to translate the site’s user interface into multiple languages and have them all available (so a site could be in French and English, let’s say). Another thing which would be relatively easy to implement would be a translation interface directly in the site, so that site content can also be translated and shown automatically if it exists for a given piece of content. This should make it easy to build multilingual sites.
Comments
Up until now, the site hasn’t had the ability for users to leave comments. Over the past two weeks we’ve built comment functionality into the site, so it’s now possible to leave comments on articles (and soon events and videos).
We’re thinking about having features like the person who created the content having control over comment administration, but we’ll have to ask around and see what people think of that.
Summary
The site is nearly ready for production deployment, there are a bunch of very small things which need to be fixed up so that it can go live at Indymedia Denmark – areas of the interface which still need translation, the ability to un-hide comments, and a short list of other stuff.
